Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow raw fish option to be set from command line #829

Merged
merged 7 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 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,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()
Expand All @@ -226,18 +236,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
8 changes: 4 additions & 4 deletions docs/autofish.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.