Commit Graph

26 Commits

Author SHA1 Message Date
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
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
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
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
6e02b89b9b Replace - with _ in default target 2014-08-23 11:35:49 +04:00
mpeterv
59603d5f39 Fixed exploded tests to work with busted 2.0 2014-08-01 17:44:15 +04:00
mpeterv
fb1c14ff80 Fixed options receiving arguments after -- 2014-03-02 12:40:16 +04:00
mpeterv
aeacbeb589 Improved error message
Report '1 times' as '1 time'
2014-02-23 16:58:39 +04:00
mpeterv
fc65c85a13 Improved command line parsing
The first character after control character is now not required to be a letter
2014-02-23 16:20:55 +04:00
mpeterv
ccad58ef50 return Parser as the module 2014-02-17 18:41:09 +04:00
mpeterv
e7aa042004 Fixed the charset of the current parser being used.
Now the global set of all control characters of all (sub)commands is used.
2014-02-09 00:18:00 +04:00
mpeterv
2a49500a01 added cli test 2014-01-26 19:02:36 +04:00
mpeterv
404ec5213a Added help message generation; Improved optional arguments handling. 2014-01-26 15:21:11 +04:00
mpeterv
c0039106f3 fixed tests: all printed data is quoted 2014-01-25 12:47:49 +04:00
mpeterv
e81aab8a5b fixed arguments from root parser not formatted 2014-01-19 15:11:09 +04:00
mpeterv
f7a0703e73 fixed crash on unknown long option 2014-01-19 14:34:42 +04:00
mpeterv
0e367c6f77 fixed ugly curry in tests 2014-01-19 14:28:08 +04:00
mpeterv
d492dc5e0f Finished working on new interface and stuff 2014-01-19 00:35:48 +04:00
mpeterv
1a52acca75 fixed test 5.1 compatibility 2014-01-13 19:01:42 +04:00
mpeterv
fe0b5f2874 renamed largparse -> argparse; imported testing setup from literal 2014-01-12 23:41:46 +04:00
mpeterv
aa0d5eae6d more tests 2014-01-06 15:08:33 +04:00
mpeterv
51b3ed4e2a updated reamde 2014-01-01 14:51:05 +04:00
mpeterv
582bdc1738 more tests, fixed wrong behaviour of joined options 2014-01-01 14:49:31 +04:00
mpeterv
ebd1c7b268 more tests, fixed some incorrect behaviour 2013-12-31 22:15:11 +04:00