mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Redesign argument storing
* Use state objects instead of tons of locals in the main function. * Use actions for storing arguments into result table. Actions are now called at the end of each invocation, with result table, target index, arguments and overwrite flag as arguments. * Remove command actions. * Improve error messages, refer to options by the last used alias instead of the main name. TODO: * Improve error messages further ("argument 'foo' is required" -> "missing argument 'foo'", etc.). * Add actions for positional arguments. * Add actions for commands (should be called with final results after parsing is over, in "innermost first" order). * Allow referring to built-in actions by strings a-la Python (e.g. action = "store_false"). * Allow setting initial value to be stored at target index for each option (perhaps use default value for that). * Add more tests, particularly for actions.
This commit is contained in:
@@ -20,7 +20,7 @@ describe("tests related to CLI behaviour #unsafe", function()
|
||||
assert.equal([[
|
||||
Usage: ]]..script..[[ [-v] [-h] <input> [<command>] ...
|
||||
|
||||
Error: too few arguments
|
||||
Error: argument 'input' is required
|
||||
]], get_output(""))
|
||||
end)
|
||||
|
||||
@@ -62,7 +62,7 @@ Did you mean 'install'?
|
||||
assert.equal([[
|
||||
Usage: ]]..script..[[ install [-f <from>] [-h] <rock> [<version>]
|
||||
|
||||
Error: too few arguments
|
||||
Error: argument 'rock' is required
|
||||
]], get_output("foo install"))
|
||||
end)
|
||||
|
||||
|
Reference in New Issue
Block a user