diff --git a/autofish.lua b/autofish.lua index cdbf872e2c..aa11d72fe4 100644 --- a/autofish.lua +++ b/autofish.lua @@ -1,5 +1,5 @@ -- handles automatic fishing jobs to limit the number of fish the fortress keeps on hand --- autofish [enable | disable] [min] [--include-raw | -r] +-- autofish [enable | disable] [min] [] --@ enable=true --@ module=true @@ -206,10 +206,20 @@ if dfhack_flags and dfhack_flags.enable then args = {dfhack_flags.enable_state and "enable" or "disable"} end --- find flags in args: +-- lookup to convert arguments to bool values. +local toBool={["true"]=true,["yes"]=true,["y"]=true,["on"]=true,["1"]=true, + ["false"]=false,["no"]=false,["n"]=false,["off"]=false,["0"]=false} + local positionals = argparse.processArgsGetopt(args, - {{"r", "toggle-raw", - handler=function() s_useRaw = not s_useRaw end} + {{"r", "raw", hasArg=true, + handler=function(optArg) + optArg=string.lower(optArg) + if toBool[optArg] ~= nil then + set_useRaw(toBool[optArg]) + else + qerror("Invalid argument to --raw \"".. optArg .."\". expected boolean") + end + end} }) load_state() @@ -226,8 +236,9 @@ elseif positionals[1] == "status" then print_status() return +-- positionals is an empty table if no positional arguments are set elseif positionals ~= nil then - -- positionals is a number? + -- check to see if passed args are numbers if positionals[1] and tonumber(positionals[1]) then -- assume we're changing setting: local newval = tonumber(positionals[1]) @@ -235,9 +246,6 @@ elseif positionals ~= nil then if not positionals[2] then set_minFish(math.floor(newval * 0.75)) end - else - -- invalid or no argument - return end if positionals[2] and tonumber(positionals[2]) then diff --git a/docs/autofish.rst b/docs/autofish.rst index dab089f5c8..97c9f71ecf 100644 --- a/docs/autofish.rst +++ b/docs/autofish.rst @@ -37,16 +37,16 @@ Positional Parameters Options ------- -``-r``, ``--toggle-raw`` - (default: on) to toggle letting the script also count your raw fish as part - of your quota. Use it a second time to disable this. +``r``, ``--raw (true | false)`` + (default: ``true``) Set whether or not raw fish should be counted in the running + total of fish in your fortress. Examples -------- ``enable autofish`` Enables the script. -``autofish -r 150`` +``autofish 150 -r true`` Sets your maximum fish to 150, and enables counting raw fish. ``autofish 300 250`` Sets your maximum fish to 300 and minimum to 250.