• 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

80.0
/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
-- Executes a script by name from the project manifest.
10
-- @param script_name [string] The key of the script in the scripts table.
11
-- @param manifest_loader [table] The manifest loader module.
12
-- @return [boolean, string] True and output if successful, false and error message otherwise.
13
local function run_script(script_name, manifest_loader)
14
  local manifest = manifest_loader.safe_load_project_manifest("project.lua")
2✔
15
  if not manifest then
2✔
NEW
16
    return false, "Failed to load project manifest."
×
17
  end
18
  local scripts = manifest.scripts or {}
2✔
19
  if not scripts or not scripts[script_name] then
2✔
20
    print(string.format(
2✔
21
      "Script '%s' not found in project.lua.",
1✔
22
      script_name
23
    ))
1✔
24
    return false, string.format(
2✔
25
      "Script '%s' not found in project.lua.",
1✔
26
      script_name
27
    )
2✔
28
  end
29
  local script = scripts[script_name]
1✔
30
  local cmd = script.cmd or script
1✔
31
  local args = script.args or {}
1✔
32
  local command = cmd
1✔
33
  if #args > 0 then
1✔
NEW
34
    command = cmd .. " " .. table.concat(args, " ")
×
35
  end
36
  print(string.format(
2✔
37
    "Running script '%s': %s",
1✔
38
    script_name,
1✔
39
    command
40
  ))
1✔
41
  local ok, exit_reason, code = os.execute(command)
1✔
42
  if ok then
1✔
43
    print(string.format(
2✔
44
      "Script '%s' completed successfully.",
1✔
45
      script_name
46
    ))
1✔
47
    return true, nil
1✔
48
  else
NEW
49
    print(string.format(
×
50
      "Script '%s' failed (reason: %s, code: %s)",
51
      script_name,
NEW
52
      tostring(exit_reason),
×
NEW
53
      tostring(code)
×
54
    ))
NEW
55
    return false, string.format(
×
56
      "Script '%s' failed (reason: %s, code: %s)",
57
      script_name,
NEW
58
      tostring(exit_reason),
×
NEW
59
      tostring(code)
×
60
    )
61
  end
62
end
63

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

77
---
78
-- Finds a matching script if the name is unambiguous.
79
-- @param name [string] The candidate script name.
80
-- @param manifest_loader [table]
81
-- @return [string|nil] The script name if unambiguous, or nil.
82
local function get_unambiguous_script(name, manifest_loader)
83
  local manifest = manifest_loader.safe_load_project_manifest("project.lua")
2✔
84
  if not manifest or not manifest.scripts then return nil end
2✔
85
  if manifest.scripts[name] then return name end
2✔
86
  return nil
1✔
87
end
88

89
---
90
-- Prints usage/help information for the `run` command.
91
-- Usage: almd run <script_name>
92
-- Executes a script defined in project.lua.
93
local function help_info()
NEW
94
  print([[
×
95
Usage: almd run <script_name>
96

97
Executes a script defined in the `scripts` table of project.lua.
98
Example:
99
  almd run test
NEW
100
]])
×
101
end
102

103
return {
1✔
104
  run_script = run_script,
1✔
105
  is_reserved_command = is_reserved_command,
1✔
106
  get_unambiguous_script = get_unambiguous_script,
1✔
107
  help_info = help_info
1✔
108
}
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