13 Commits

Author SHA1 Message Date
Peter Melnichenko
7a8236751f Add a test for a automatic invocation of underused option with default value 2018-03-17 14:37:06 +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
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
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
01cc387863 Spec cleanups 2015-03-13 15:19:33 +03:00
mpeterv
59603d5f39 Fixed exploded tests to work with busted 2.0 2014-08-01 17:44:15 +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
57f8d46ba3 Reworked default values
* Better out-of-the-box behavior: commonly used feature should work without configuration. Only use default value if argument/option was not used at all.
* Add `defmode` field so that old behaviour can be used, too.
2014-02-28 17:06:07 +04:00
mpeterv
3e6dc54201 If an option with a default value is underused, invoke it more 2014-02-20 12:48:51 +04:00
mpeterv
ccad58ef50 return Parser as the module 2014-02-17 18:41:09 +04:00
mpeterv
e81aab8a5b fixed arguments from root parser not formatted 2014-01-19 15:11:09 +04:00
mpeterv
fe0b5f2874 renamed largparse -> argparse; imported testing setup from literal 2014-01-12 23:41:46 +04:00
mpeterv
3d58d8649d added default values 2014-01-06 15:51:21 +04:00