[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How to choose betweem competing modules (Was: Rock that parses command lines?
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 15 Jul 2016 22:57:52 +0200
2016-07-15 20:37 GMT+02:00 Jonathan Goble <jcgoble3@gmail.com>:
> On Fri, Jul 15, 2016 at 2:29 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> Someone posted an announcement for a rock that takes your
>> help string and parses your command line. It turns 'args' into
>> a keyed table, e.g. {"-d", "s=specify"} --> {d=true, s="specify"}
>> and tests whether the option is documented.
>>
>> This seems to be something that can neatly be done in pure Lua
>> but the only rock I could find is 'commandlineui' which seems to be
>> heavily system-dependent: e.g. it wants me to install GDBM.
>> I don't think that's the one I want.
>
> Here's a thread from April in which multiple options were suggested:
>
> http://lua-users.org/lists/lua-l/2016-04/threads.html#00083
>
> Are you looking for one of those?
It took some time to read them all.
I'm looking for something available on luarocks. That disqualifies
all that only sit on GitHub.
I could find argparse, optparse and pl.lapp. Installed them,
required them in an interactive session and tried to find
out how they work. I experienced the usual brief longing
for the Python 'docstring' feature, but my 'ihelp' can usually
find LDoc-like comments if the author has not been too
clever for me.
'argparse' is just one function, a parser factory, but the
source code is not LDoc-commented.
> help(argparse)
return function(...)
return Parser(default_cmdline[0]):add_help(true)(...)
end
I shall have to read the documentation. Not on the shortlist.
optparse is a table, one field called 'prototype', also a table.
This author hides everything in metatables. Also does not
respond to the probings of 'ihelp'. Not on the shortlist.
lapp is a table with several fields, one of which looks promising.
> help(lapp)
Contents: add_type assert callback error open process_options_string
quit show_usage_error
> help(lapp.process_options_string)
--- process a Lapp options string.
-- Usually called as `lapp()`.
-- @string str the options text
-- @tparam {string} args a table of arguments (default is `_G.arg`)
-- @return a table with parameter-value pairs
OK, this one is on the shortlist. I may need to read its docs after
all, in which case the others come back into contention.