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

nightconcept / almandine / 14846535458

05 May 2025 09:22PM UTC coverage: 32.421% (-35.5%) from 67.965%
14846535458

push

github

web-flow
fix: Change init module to be e2e testable (#17)

91 of 420 new or added lines in 11 files covered. (21.67%)

462 of 1425 relevant lines covered (32.42%)

1.34 hits per line

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

93.48
/src/modules/init.lua
1
--- Init Module
2
--- Provides interactive project initialization and manifest creation.
3
--
4

5
---TODO: remove this once we have a pass over this file
6
--luacheck: ignore
7

8
-- Ensure relative paths work for requires within the project
9
local filesystem_utils = require("utils.filesystem")
2✔
10
package.path = filesystem_utils.join_path("src", "?.lua") .. ";" .. package.path
2✔
11
package.path = filesystem_utils.join_path("src", "lib", "?.lua") .. ";" .. package.path
2✔
12

13
---@class InitDeps
14
---@field prompt fun(msg: string, default: string|nil): string|nil Function to prompt user for input.
15
---@field println fun(...) Function to print output to the console.
16
---@field save_manifest fun(manifest: table): boolean, string? Function to save the manifest table.
17
---@field exit fun(code: number|nil) Function to exit the application.
18
---@field printer table Printer utility with stdout/stderr methods.
19

20
--- Internal helper function to prompt the user.
21
--- Uses the injected prompt function from dependencies.
22
---@param deps InitDeps The dependency table.
23
---@param msg string The prompt message.
24
---@param default string|nil The optional default value.
25
---@return string|nil The user's input or the default value.
26
local function _prompt_user(deps, msg, default)
27
  local formatted_msg = msg
30✔
28
  if default then
30✔
29
    formatted_msg = formatted_msg .. " [" .. default .. "]"
12✔
30
  end
31
  formatted_msg = formatted_msg .. ": "
30✔
32

33
  local input = deps.prompt(formatted_msg, default)
30✔
34

35
  -- Original logic retained: If input is empty string or nil, return default.
36
  -- Note: The injected prompt function might already handle the nil case depending on implementation.
37
  if input == "" or input == nil then
30✔
38
    return default
10✔
39
  else
40
    return input
20✔
41
  end
42
end
43

44
--- Prints usage/help information for the `init` command.
45
--- Usage: almd init
46
--- Initializes a new Almandine project interactively.
47
local function help_info()
NEW
48
  return [[
×
49
Usage: almd init
50

51
Interactively initializes a new Almandine project and creates a project.lua manifest.
NEW
52
]]
×
53
end
54

55
--- Initializes a new Almandine project by interactively prompting the user for manifest fields and writing project.lua.
56
---@param deps InitDeps Table containing dependency injected functions.
57
---@return boolean success True if successful, false otherwise.
58
---@return string|nil message Success message for stdout.
59
---@return string|nil error_message Error message for stderr.
60
function init_project(deps)
2✔
61
  deps.printer.stdout("Almandine Project Initialization")
3✔
62
  deps.printer.stdout("-------------------------------")
3✔
63
  local manifest = {}
3✔
64

65
  manifest.name = _prompt_user(deps, "Project name", "my-lua-project")
3✔
66
  manifest.type = "application" -- Defaulting for now, could prompt later
3✔
67
  manifest.version = _prompt_user(deps, "Project version", "0.0.1")
3✔
68
  manifest.license = _prompt_user(deps, "License", "MIT")
3✔
69
  manifest.description = _prompt_user(deps, "Description", "A sample Lua project using Almandine.")
3✔
70

71
  manifest.scripts = {}
3✔
72
  deps.println("Add scripts (leave name empty to finish):")
3✔
73
  while true do
74
    local script_name = _prompt_user(deps, "  Script name")
6✔
75
    if not script_name or script_name == "" then
6✔
76
      break
77
    end
78
    local script_cmd = _prompt_user(deps, "    Command for '" .. script_name .. "'")
3✔
79
    manifest.scripts[script_name] = script_cmd
3✔
80
  end
81
  -- Ensure a default 'run' script is present if not set
82
  if not manifest.scripts["run"] or manifest.scripts["run"] == "" then
3✔
83
    manifest.scripts["run"] = "lua src/main.lua"
3✔
84
    deps.println("Default 'run' script added: lua src/main.lua") -- Inform user
3✔
85
  end
86

87
  manifest.dependencies = {}
3✔
88
  deps.println("Add dependencies (leave name empty to finish):")
3✔
89
  while true do
90
    local dep_name = _prompt_user(deps, "  Dependency name")
6✔
91
    if not dep_name or dep_name == "" then
6✔
92
      break
93
    end
94
    local dep_ver = _prompt_user(deps, "    Version/source for '" .. dep_name .. "'")
3✔
95
    manifest.dependencies[dep_name] = dep_ver
3✔
96
  end
97

98
  local ok, err = deps.save_manifest(manifest)
3✔
99
  if not ok then
3✔
NEW
100
    return false, nil, "Error: Could not write project.lua - " .. tostring(err)
×
101
  end
102
  deps.println("\nproject.lua written successfully.")
3✔
103
  return true, "Project initialized successfully."
3✔
104
end
105

106
return {
2✔
107
  init_project = init_project,
2✔
108
  help_info = help_info,
2✔
109
}
2✔
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