From 6b0718ae7437195fbc84259e3a348f3f7b609bb0 Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:58:11 -0600 Subject: [PATCH 1/6] Make raw fish option a command line toggle. --- autofish.lua | 25 +++++++++++++++++-------- docs/autofish.rst | 6 +++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/autofish.lua b/autofish.lua index cdbf872e2c..f173a5a4b7 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,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() @@ -226,8 +237,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 +247,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..c4a00bdc28 100644 --- a/docs/autofish.rst +++ b/docs/autofish.rst @@ -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 `` + (default: on) Set whether or not raw fish should be counted in the running + total of fish in your fortress. Examples -------- From bab5b4c87159923149d7436dffa435a99483fc58 Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:45:26 -0600 Subject: [PATCH 2/6] Update autofish.lua Missed optional argument [] Co-authored-by: Myk --- autofish.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autofish.lua b/autofish.lua index f173a5a4b7..12d0f45fd6 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] +-- autofish [enable | disable] [min] [] --@ enable=true --@ module=true From 48bb812f5ee68c25c883f3990163310481f52a7d Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:45:55 -0600 Subject: [PATCH 3/6] Update docs/autofish.rst fix text formatting of command output Co-authored-by: Myk --- docs/autofish.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/autofish.rst b/docs/autofish.rst index c4a00bdc28..48d23bee81 100644 --- a/docs/autofish.rst +++ b/docs/autofish.rst @@ -37,7 +37,7 @@ Positional Parameters Options ------- -``r``, ``--raw `` +``r``, ``--raw (true | false)`` (default: on) Set whether or not raw fish should be counted in the running total of fish in your fortress. From 2006c7b9fd963c0e2a999151ce45bf9155c363f5 Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:46:16 -0600 Subject: [PATCH 4/6] Update docs/autofish.rst fix wording of command description Co-authored-by: Myk --- docs/autofish.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/autofish.rst b/docs/autofish.rst index 48d23bee81..25e39b82f5 100644 --- a/docs/autofish.rst +++ b/docs/autofish.rst @@ -38,7 +38,7 @@ Options ------- ``r``, ``--raw (true | false)`` - (default: on) Set whether or not raw fish should be counted in the running + (default: ``true``) Set whether or not raw fish should be counted in the running total of fish in your fortress. Examples From 068fb57744cbd2855ce6eb38ba6b7b10b13bf19e Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:49:35 -0600 Subject: [PATCH 5/6] remove return, qerror throws --- autofish.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/autofish.lua b/autofish.lua index 12d0f45fd6..aa11d72fe4 100644 --- a/autofish.lua +++ b/autofish.lua @@ -218,7 +218,6 @@ local positionals = argparse.processArgsGetopt(args, set_useRaw(toBool[optArg]) else qerror("Invalid argument to --raw \"".. optArg .."\". expected boolean") - return end end} }) From d9e6935c212eaefc93fd3c3a1827c706893ddb90 Mon Sep 17 00:00:00 2001 From: Andriel Chaoti <3628387+AndrielChaoti@users.noreply.github.com> Date: Sat, 9 Sep 2023 12:52:27 -0600 Subject: [PATCH 6/6] forgot to update the example texts --- docs/autofish.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/autofish.rst b/docs/autofish.rst index 25e39b82f5..97c9f71ecf 100644 --- a/docs/autofish.rst +++ b/docs/autofish.rst @@ -46,7 +46,7 @@ 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.