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

nightconcept / almandine / 14716629923

28 Apr 2025 07:54PM UTC coverage: 95.996%. First build
14716629923

push

github

web-flow
feat: Initial features (#1)

863 of 899 new or added lines in 16 files covered. (96.0%)

863 of 899 relevant lines covered (96.0%)

1.99 hits per line

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

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

45
---
46
-- Determines if a string is a reserved command name.
47
-- @param name [string]
48
-- @return [boolean]
49
local function is_reserved_command(name)
50
  local reserved = {
2✔
51
    ["init"] = true,
2✔
52
    ["add"] = true,
2✔
53
    ["i"] = true,
2✔
54
    ["install"] = true,
2✔
55
    ["in"] = true,
2✔
56
    ["ins"] = true,
2✔
57
    ["remove"] = true,
2✔
58
    ["rm"] = true,
2✔
59
    ["uninstall"] = true,
2✔
60
    ["un"] = true,
2✔
61
    ["update"] = true,
2✔
62
    ["up"] = true,
2✔
63
    ["upgrade"] = true,
2✔
64
    ["run"] = true,
2✔
65
    ["list"] = true,
2✔
66
  }
67
  return reserved[name] == true
2✔
68
end
69

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

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

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

100
return {
1✔
101
  run_script = run_script,
1✔
102
  is_reserved_command = is_reserved_command,
1✔
103
  get_unambiguous_script = get_unambiguous_script,
1✔
104
  help_info = help_info,
1✔
105
}
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