• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nightconcept / almandine / 14715174283

28 Apr 2025 06:32PM UTC coverage: 37.748%. First build
14715174283

push

github

web-flow
Merge 789647aa5 into 78f97e22e

477 of 566 new or added lines in 14 files covered. (84.28%)

1693 of 4485 relevant lines covered (37.75%)

11.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.84
/src/modules/add.lua
1
--[[
2
  Add Command Module
3

4
  Provides functionality to add a dependency to the project manifest and download it to the lib directory.
5
]]--
6

7
--- Adds a dependency to the project manifest and downloads it.
8
-- @param dep_name string|nil Dependency name to add. If nil, inferred from source URL.
9
-- @param dep_source string Dependency source string (URL or table with url/path).
10
-- @param load_manifest function Function to load the manifest.
11
-- @param save_manifest function Function to save the manifest.
12
-- @param ensure_lib_dir function Function to ensure lib dir exists.
13
-- @param downloader table utils.downloader module.
14
local function add_dependency(dep_name, dep_source, load_manifest, save_manifest, ensure_lib_dir, downloader)
15
  ensure_lib_dir()
4✔
16
  local manifest, err = load_manifest()
4✔
17
  if not manifest then print(err) return end
4✔
18
  manifest.dependencies = manifest.dependencies or {}
4✔
19

20
  -- If dep_name is missing, infer from URL (filename minus .lua)
21
  if (not dep_name or dep_name == "") and type(dep_source) == "string" then
4✔
22
    local fname = dep_source:match("([^/]+)$")
1✔
23
    if fname then
1✔
24
      dep_name = fname:gsub("%.lua$", "")
1✔
25
    else
NEW
26
      print("Could not infer dependency name from source URL.")
×
NEW
27
      return
×
28
    end
29
  end
30
  if not dep_name or not dep_source then
4✔
31
    -- Nothing to add, exit early
32
    return
1✔
33
  end
34
  manifest.dependencies[dep_name] = dep_source
3✔
35
  local ok, err2 = save_manifest(manifest)
3✔
36
  if not ok then print(err2) return end
3✔
37
  print(string.format("Added dependency '%s' to project.lua.", dep_name))
3✔
38

39
  local name, source = dep_name, dep_source
3✔
40
  local out_path
41
  local url
42
  if type(source) == "table" and source.url and source.path then
3✔
43
    url = source.url
1✔
44
    out_path = source.path
1✔
45
  else
46
    url = source
2✔
47
    local filesystem_utils = require("utils.filesystem")
2✔
48
    out_path = filesystem_utils.join_path(
4✔
49
      "src",
2✔
50
      "lib",
2✔
51
      name .. ".lua"
2✔
52
    )
2✔
53
  end
54
  local ok3, err3 = downloader.download(url, out_path)
3✔
55
  if ok3 then
3✔
56
    print(string.format("Downloaded %s to %s",
6✔
57
      name, out_path))
6✔
58
  else
NEW
59
    print(string.format("Failed to download %s: %s", name, err3))
×
60
  end
61
end
62

63
---
64
-- Prints usage/help information for the `add` command.
65
-- Usage: almd add <dep_name> <source>
66
-- Adds a dependency to the project manifest and downloads it to the lib directory.
67
local function help_info()
NEW
68
  print([[
×
69
Usage: almd add <dep_name> <source>
70
       almd add <source>
71

72
Adds a dependency to your project. <dep_name> is the name (optional if source is a GitHub raw URL), <source> is a URL or
73
version specifier.
74
If <dep_name> is omitted, it will be inferred from the filename in the source URL.
75
Examples:
76
  almd add lunajson https://github.com/grafi-tt/lunajson/raw/master/lunajson.lua
77
  almd add https://github.com/grafi-tt/lunajson/raw/master/lunajson.lua
NEW
78
]])
×
79
end
80

81
return {
1✔
82
  add_dependency = add_dependency,
1✔
83
  help_info = help_info
1✔
84
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc