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 2 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
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>
AndrielChaoti marked this conversation as resolved.
Show resolved Hide resolved

--@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for return -- qerror throws

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>``
AndrielChaoti marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the example -r commandline below should be updated too

(default: on) Set whether or not raw fish should be counted in the running
AndrielChaoti marked this conversation as resolved.
Show resolved Hide resolved
total of fish in your fortress.

Examples
--------
Expand Down