Skip to content

Commit

Permalink
Make raw fish option a command line toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrielChaoti committed Sep 6, 2023
1 parent 628adeb commit 6b0718a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 17 additions & 8 deletions autofish.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- handles automatic fishing jobs to limit the number of fish the fortress keeps on hand
-- autofish [enable | disable] <max> [min] [--include-raw | -r]
-- autofish [enable | disable] <max> [min] <options>

--@ enable=true
--@ module=true
Expand Down Expand Up @@ -206,10 +206,21 @@ 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")
return
end
end}
})

load_state()
Expand All @@ -226,18 +237,16 @@ 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])
set_maxFish(newval)
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
Expand Down
6 changes: 3 additions & 3 deletions docs/autofish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ 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: on) Set whether or not raw fish should be counted in the running
total of fish in your fortress.

Examples
--------
Expand Down

0 comments on commit 6b0718a

Please sign in to comment.