error on invalid phase names

develop
myk002 2021-05-21 06:33:33 -07:00
parent 0409b7bca5
commit 1aaed3a6ed
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 11 additions and 6 deletions

@ -33,13 +33,15 @@ See the online DFHack documentation for more examples and details.
function print_help() print(help_text) end function print_help() print(help_text) end
valid_phases = utils.invert{ local valid_phase_list = {
'dig', 'dig',
'build', 'build',
'place', 'place',
'query', 'query',
} }
valid_phases = utils.invert(valid_phase_list)
local function parse_cursor(opts, arg) local function parse_cursor(opts, arg)
local _, _, x, y, z = arg:find('^(%d+),(%d+),(%d+)$') local _, _, x, y, z = arg:find('^(%d+),(%d+),(%d+)$')
if not x then if not x then
@ -73,10 +75,12 @@ local function parse_positionals(opts, args, start_argidx)
local auto_phase = true local auto_phase = true
local phase = args[argidx] local phase = args[argidx]
while phase do while phase do
if valid_phases[phase] then if not valid_phases[phase] then
qerror(('unknown phase: "%s"; expected one of: %s'):
format(phase, table.concat(valid_phase_list, ', ')))
end
auto_phase = false auto_phase = false
opts[phase] = true opts[phase] = true
end
argidx = argidx + 1 argidx = argidx + 1
phase = args[argidx] phase = args[argidx]
end end

@ -49,8 +49,9 @@ function test.parse_gui_commandline()
opts) opts)
opts = {} opts = {}
b.parse_gui_commandline(opts, {'imaname', 'garbagephase'}) expect.error_match('unknown phase',
expect.table_eq({auto_phase=true, name='imaname'}, opts) function() b.parse_gui_commandline(
opts, {'imaname', 'garbagephase'}) end)
end end
function test.parse_commandline() function test.parse_commandline()