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

nightconcept / almandine / 14748071543

30 Apr 2025 06:21AM UTC coverage: 68.293% (-12.0%) from 80.336%
14748071543

push

github

web-flow
fix: add (#13)

30 of 263 new or added lines in 4 files covered. (11.41%)

27 existing lines in 3 files now uncovered.

1344 of 1968 relevant lines covered (68.29%)

1.94 hits per line

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

98.33
/src/modules/run.lua
1
--[[
2
  Run Command Module
3

4
  Provides logic for executing scripts defined in the `scripts` table of project.lua.
5
  Used by the main CLI entrypoint for the `run` command and for direct script invocation if unambiguous.
6
]]
7
--
8

9
---
10
-- Executes a script by name from the project manifest using provided dependencies.
11
-- @param script_name string The key of the script in the scripts table.
12
-- @param deps table Dependencies: { manifest_loader, executor? }.
13
--               `manifest_loader` is a function or module with safe_load_project_manifest.
14
--               `executor` is an optional function for command execution (defaults to os.execute).
15
-- @return boolean, string True and output if successful, false and error message otherwise.
16
local function run_script(script_name, deps)
17
  local manifest_loader = deps.manifest_loader
6✔
18
  local executor = deps.executor or os.execute
6✔
19

20
  -- Handle manifest_loader being either a function or a module
21
  local load_manifest = type(manifest_loader) == "function" and manifest_loader
6✔
22
    or manifest_loader.safe_load_project_manifest
6✔
23

24
  local manifest = load_manifest("project.lua")
6✔
25
  if not manifest then
6✔
26
    return false, "Failed to load project manifest."
1✔
27
  end
28
  local scripts = manifest.scripts or {}
5✔
29
  if not scripts or not scripts[script_name] then
5✔
30
    print(string.format("Script '%s' not found in project.lua.", script_name))
2✔
31
    return false, string.format("Script '%s' not found in project.lua.", script_name)
2✔
32
  end
33
  local script = scripts[script_name]
3✔
34
  local cmd = script.cmd or script
3✔
35
  local args = script.args or {}
3✔
36
  local command = cmd
3✔
37
  if #args > 0 then
3✔
38
    command = cmd .. " " .. table.concat(args, " ")
1✔
39
  end
40
  print(string.format("Running script '%s': %s", script_name, command))
3✔
41
  local ok, exit_reason, code = executor(command)
3✔
42
  if ok then
3✔
43
    print(string.format("Script '%s' completed successfully.", script_name))
2✔
44
    return true, nil
2✔
45
  else
46
    print(
2✔
47
      string.format("Script '%s' failed (reason: %s, code: %s)", script_name, tostring(exit_reason), tostring(code))
1✔
48
    )
49
    return false,
1✔
50
      string.format("Script '%s' failed (reason: %s, code: %s)", script_name, tostring(exit_reason), tostring(code))
1✔
51
  end
52
end
53

54
---
55
-- Determines if a string is a reserved command name.
56
-- @param name string
57
-- @return boolean
58
local function is_reserved_command(name)
59
  local reserved = {
2✔
60
    ["init"] = true,
2✔
61
    ["add"] = true,
2✔
62
    ["i"] = true,
2✔
63
    ["install"] = true,
2✔
64
    ["in"] = true,
2✔
65
    ["ins"] = true,
2✔
66
    ["remove"] = true,
2✔
67
    ["rm"] = true,
2✔
68
    ["uninstall"] = true,
2✔
69
    ["un"] = true,
2✔
70
    ["update"] = true,
2✔
71
    ["up"] = true,
2✔
72
    ["upgrade"] = true,
2✔
73
    ["run"] = true,
2✔
74
    ["list"] = true,
2✔
75
  }
76
  return reserved[name] == true
2✔
77
end
78

79
---
80
-- Finds a matching script if the name is unambiguous using provided dependencies.
81
-- @param name string The candidate script name.
82
-- @param deps table Dependencies: { manifest_loader }.
83
--               `manifest_loader` is a function or module with safe_load_project_manifest.
84
-- @return string|nil The script name if unambiguous, or nil.
85
local function get_unambiguous_script(name, deps)
86
  local manifest_loader = deps.manifest_loader
2✔
87
  -- Handle manifest_loader being either a function or a module
88
  local load_manifest = type(manifest_loader) == "function" and manifest_loader
2✔
89
    or manifest_loader.safe_load_project_manifest
2✔
90

91
  local manifest = load_manifest("project.lua")
2✔
92
  if not manifest or not manifest.scripts then
2✔
UNCOV
93
    return nil
×
94
  end
95
  if manifest.scripts[name] then
2✔
96
    return name
1✔
97
  end
98
  return nil
1✔
99
end
100

101
---
102
-- Prints usage/help information for the `run` command.
103
-- Usage: almd run <script_name>
104
-- Executes a script defined in project.lua.
105
local function help_info()
106
  print([[
2✔
107
Usage: almd run <script_name>
108

109
Executes a script defined in the `scripts` table of project.lua.
110
Example:
111
  almd run test
112
]])
1✔
113
end
114

115
return {
1✔
116
  run_script = run_script,
1✔
117
  is_reserved_command = is_reserved_command,
1✔
118
  get_unambiguous_script = get_unambiguous_script,
1✔
119
  help_info = help_info,
1✔
120
}
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