Commit Graph

95 Commits

Author SHA1 Message Date
Peter Melnichenko
dfb012dba0 Add support for grouping elements in help message 2018-04-08 14:03:45 +03:00
Peter Melnichenko
e33a6ed563 Support -- as an option 2018-04-07 23:21:06 +03:00
Peter Melnichenko
4f72bfeb8e Add hidden property, unlisting elements from usage and help 2018-04-07 22:09:18 +03:00
Peter Melnichenko
28604e8411 Rework usage message building and support arguments in mutexes
Ref #11.
2018-03-18 23:28:01 +03:00
Peter Melnichenko
aa740c4270 Allow using separate converters for each argument
When converting an argument in a position, if there is a function
in the same position in provided converer array, use
it as a converter function.

This allows using an array of functions as the value of `convert` property,
with each function applied to corresponding argument of a multi-argument option.

Ref #14.
2018-03-17 14:53:12 +03:00
Peter Melnichenko
7a8236751f Add a test for a automatic invocation of underused option with default value 2018-03-17 14:37:06 +03:00
Peter Melnichenko
8d929db27c Add a test for usage generation for vararg options and mutexes 2018-03-17 14:31:55 +03:00
Peter Melnichenko
d77cd6a5d1 Add tests for property validation 2018-03-17 14:26:45 +03:00
Peter Melnichenko
caf69bc943 Add a test for concat action + overwrite interaction 2018-03-17 14:09:54 +03:00
Peter Melnichenko
4d06371a07 Fix some line length warnings 2018-03-17 13:34:50 +03:00
Peter Melnichenko
3a43d528c6 Fix whitespace warnings 2018-03-16 17:26:31 +03:00
mpeterv
413d3e32f1 Pass command name to command actions 2015-12-09 14:02:23 +03:00
mpeterv
247ed9e874 New Parser/Command property 'command_target'
Allows saving name of used command in a field of result target.
Helpful when command callbacks are stored in a table with names as keys
or when they are in submodules of some namespace.

Example:

    local parser = argparse():command_target("command")
    -- Add commands...
    local args = parser:parse()
    require("namespace." .. args.command).run(args)
2015-11-23 15:54:31 +03:00
mpeterv
79952deb42 Respect empty initial value in 'append' and 'concat' actions 2015-10-31 20:02:56 +03:00
mpeterv
4fb2991fb2 Add 'concat' action 2015-10-31 19:48:37 +03:00
mpeterv
38b6eb1392 Add :init() property
Allows setting initial stored value. Can be also set using
:default() with a non-string argument.
2015-10-31 19:19:56 +03:00
mpeterv
8343a41dfa Implement string aliases for actions
Added built-in "store_false" action.
2015-10-31 19:09:12 +03:00
mpeterv
4f9841dec6 Implement command actions 2015-10-31 15:50:23 +03:00
mpeterv
decd2040fa Add actions for arguments 2015-10-30 15:18:24 +03:00
mpeterv
babe715548 Change error messages for missing elements
* For arguments: "argument 'foo' is required" -> "missing argument 'foo'"
* For options: "option '--foo' must be used at least 1 time" ->
  "missing option '--foo'"
2015-10-30 15:13:30 +03:00
mpeterv
93522f1856 Add more action tests 2015-10-30 15:04:45 +03:00
mpeterv
247c8a9cce 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.
2015-10-29 21:00:49 +03:00
mpeterv
7134d25ca5 Add coverage gathering 2015-09-24 18:55:10 +03:00
Kyle McLamb
0fedcdeade Add handle_options property to Parser
When `parser:handle_options(true)` (the default), the parser will behave as
before.

When `parser:handle_options(false)`, all options will be passed verbatim
to the argument list, as if the input included double-hyphens.
2015-06-17 04:06:41 -04:00
mpeterv
85809c8ad4 Reorder properties
Move more common properties to the front of property lists,
so that they can be passed as constructor arguments.
E.g.

parser:option "-p" "--port"
   :description "Port number."
   :default "8080"
   :convert(tonumber)

can now be expressed as

parser:option("-p --port", "Port number.", "8080", tonumber)
2015-06-09 22:27:32 +03:00
mpeterv
44fd3b3cb8 Remove 'aliases' property
Allow setting several names using 'name' property instead, e.g.
':name "-f --foo"' instead of ':aliases {"-f", "--foo"}'.

This change breaks documented interface of 0.3.x.
2015-06-09 22:08:16 +03:00
mpeterv
ff9abac990 Allow using multiple constructor arguments for configuring elements
Disable undocumented ability to specify aliases as arguments
for constructors, e.g. parser:option("-f", "--foo"), and instead
order properties and pass constructor arguments to them.
E.g. parser:argument("foo", "A foo that bars") sets argument
name to foo and description to "A foo that bars".

TODO: remove "aliases" property, instead allow setting several
names in one string by separating them using space.
TODO: reorder properties so that most useful ones could be used
as constructor arguments.
2015-06-09 21:56:36 +03:00
mpeterv
476ad19de8 Avoid printing space at the end of line 2015-03-13 15:40:24 +03:00
mpeterv
01cc387863 Spec cleanups 2015-03-13 15:19:33 +03:00
mpeterv
0da90dc597 Print \n instead of \r\n 2015-03-13 15:12:06 +03:00
mpeterv
bd5fd00e6c Custom target should not affect usage and help message generation 2014-08-25 13:51:08 +04:00
mpeterv
b02536d6ba Fixed - being replaced with _ in custom targets
Default argname for options is now default target in brackets
2014-08-25 13:44:26 +04:00
mpeterv
6e02b89b9b Replace - with _ in default target 2014-08-23 11:35:49 +04:00
mpeterv
b8766c8cdf Improved usage message generation
Put options taking variable number of arguments after positional arguments
2014-08-21 15:24:54 +04:00
mpeterv
8c16eca398 Revert autoadding of <> to custom argnames 2014-08-06 13:33:50 +04:00
mpeterv
4b97d03bf5 Added show_default field 2014-08-06 13:02:29 +04:00
mpeterv
59603d5f39 Fixed exploded tests to work with busted 2.0 2014-08-01 17:44:15 +04:00
mpeterv
d1386c1d96 Add brackets to argname automatically
Updated aux files
2014-04-24 21:27:22 +04:00
mpeterv
b42960c0da Added another test 2014-03-09 14:44:19 +04:00
mpeterv
7bf5777413 Added mutually exclusive groups 2014-03-09 14:28:55 +04:00
mpeterv
c605f248ad Better name inference 2014-03-08 16:25:54 +04:00
mpeterv
2d0faa258d Argname can be an array 2014-03-08 16:04:40 +04:00
mpeterv
b4c51e84de Make add_help an actual field 2014-03-02 19:27:37 +04:00
mpeterv
fb1c14ff80 Fixed options receiving arguments after -- 2014-03-02 12:40:16 +04:00
mpeterv
454ef54aa3 Removed :usage() hooks for arguments and options 2014-03-02 11:51:25 +04:00
mpeterv
f24cfe9627 Got rid of :prepare() 2014-03-02 02:03:44 +04:00
mpeterv
db3e21e944 Refactoring: added sanity checks in setters 2014-03-02 00:49:44 +04:00
mpeterv
73467e2836 Fixed usage messages in subcommands corrupted after several usages 2014-03-01 16:41:14 +04:00
mpeterv
8cefeb1ef7 Updated README; use u in defmode as a flag instead of c 2014-03-01 15:05:36 +04:00
mpeterv
d601f54dce Improved usage messages for default values 2014-03-01 14:43:20 +04:00