-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.lua
More file actions
70 lines (49 loc) · 1.27 KB
/
tasks.lua
File metadata and controls
70 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- build.lua
local tasks = {}
--------------------------------------------------
-- Utilities
--------------------------------------------------
local function run(cmd)
print("> " .. cmd)
local pipe = io.popen(cmd .. " 2>&1")
if not pipe then
error("failed to start command")
end
local output = pipe:read("*a")
local ok = pipe:close()
if output and output ~= "" then
print(output)
end
if ok == false then
error("command failed: " .. cmd)
end
end
local function task(name, fn)
tasks[name] = fn
end
--------------------------------------------------
-- Tasks
--------------------------------------------------
task("docs", function()
run("ldoc -c config.ld .")
end)
task("test", function()
run("lua tests/run_all.lua")
end)
task("all", function()
tasks.docs()
tasks.test()
end)
--------------------------------------------------
-- CLI
--------------------------------------------------
local selected = (_G.arg and _G.arg[1]) or "all"
if not tasks[selected] then
io.stderr:write("Unknown task: " .. tostring(selected) .. "\n\n")
io.stderr:write("Available tasks:\n")
for name in pairs(tasks) do
io.stderr:write(" - " .. name .. "\n")
end
os.exit(1)
end
tasks[selected]()