forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautonestbox.lua
More file actions
51 lines (41 loc) · 1.15 KB
/
autonestbox.lua
File metadata and controls
51 lines (41 loc) · 1.15 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
local _ENV = mkmodule('plugins.autonestbox')
local argparse = require('argparse')
local function is_int(val)
return val and val == math.floor(val)
end
local function is_positive_int(val)
return is_int(val) and val > 0
end
local function process_args(opts, args)
if args[1] == 'help' then
opts.help = true
return
end
return argparse.processArgsGetopt(args, {
{'h', 'help', handler=function() opts.help = true end},
})
end
function parse_commandline(opts, ...)
local positionals = process_args(opts, {...})
if opts.help then return end
local in_ticks = false
for _,arg in ipairs(positionals) do
if in_ticks then
arg = tonumber(arg)
if not is_positive_int(arg) then
qerror('number of ticks must be a positive integer: ' .. arg)
else
opts.ticks = arg
end
in_ticks = false
elseif arg == 'ticks' then
in_ticks = true
elseif arg == 'now' then
opts.now = true
end
end
if in_ticks then
qerror('missing number of ticks')
end
end
return _ENV