What exactly are "nested commands"? You mean like "apt get" and "apt
update" or git with sub commands? That could easily be solved with
any CL parser by fetching the command first and then deciding which
parser to use - or more generally what module / class to use to handle
the command. I would not want to have all option handling in one
place anyway when there are several sub commands - this soon gets
unmanageable.
Yes, so we are both in agreement here. Having all the code in one place
quickly gets unmanageable. Flopp addresses this by making every command
(including the top level one) a separate Flopp::Command which encapsulates
the specific logic for parsing, exactly as you suggest. In this sense, you
can nest commands as many levels deep as you want, alias them in different
places with different names, etc.
However, because the nesting is aware of each other and not just a side
effect of the top level option parser, documentation is generated much more
seamlessly, and in general the parser produces a useful nested data
structure which lets you implement logic where it belongs w.r.t. a specific
command. The only example I have of this and where Flopp was originally
developed is in teapot.
> ARGV splits,
What is that?
Just a name I came up for when you write "--" and expect the command to
only process stuff on the left while passing stuff on the right to a
script/sub-process, if any. In Flopp, you just write "split :rest" and you
get documentation, parsing, and the attribute exposed in the command
instance 
> parsing arbitrary tokens (in the future supporting autocomplete)
OptionParser supports autocompletion:
$ ruby -r optparse -e 'OptionParser.new {|o| o.on("--foo"){|v|p
"foo"}}.parse!; p ARGV' -- --foo abc
"foo"
["abc"]
$ ruby -r optparse -e 'OptionParser.new {|o| o.on("--foo"){|v|p
"foo"}}.parse!; p ARGV' -- --fo abc
"foo"
["abc"]
$ ruby -r optparse -e 'OptionParser.new {|o| o.on("--foo"){|v|p
"foo"}}.parse!; p ARGV' -- --f abc
"foo"
["abc"]
I meant auto-completion in the sense you can tab-complete at a given point
in the parser and it returns all valid tokens that could come next. In
order to do this you need to know the entire parser - and I don't think
this is really possible with OptionParser with nested commands, for
example. The behaviour shown above is not really what I was suggesting,
and, IMHO, is very dangerous. It might lead to people using a command, a
new option being introduced, and then that original command does something
different.. unless that command now just breaks because the option is
ambiguous, also a bad outcome.
Flopp is very explicit, but it's also easy to specify short and long
options, etc, such as:
option '-i/--in/--root <path>', "Set the root path for doing stuff"
This will set @options[:root] to whatever you specify with one of those
three options. There is no automatic short/long options, etc. The last
option is used as the key unless it's specified explicitly.
> and automatic
> documentation for both options and nested commands.
Automated documentation is done by OptionParser already.
Not in a way that supports sub-commands easily AFAIK. It's also pretty
plain output. In Flopp, only one mode of output is supported at the moment,
but I want to have two modes of help output, --help and -h, long help and
short help respectively. Ideally, long help is more similar to a man page.
In addition, if you specify a command line, along with --help, it will
parse as much as possible into the help, with potential explanations, e.g.
if you choose --verbose --help, the --verbose option in the help output
could be documented. Ideally, the same with things like `one` and `many`
tokens, so that if you, say, wrote teapot --help build Run/MyProject it
could even give you application specific output relating to "Run/MyProject"
which has some description/documentation associated with it. This is a big
usability thing to me so I'll be working in this area next.
> In the end I got sick of
> fighting with Trollop so decided to roll my own. I will be using flopp
for
> all my command line tools now.
I find it preferable to use something in the standard library. But of
course everybody's mileage differs.
Fair enough. My opinion is that the standard library should be simplified
and kept as small as possible. Otherwise, it's hard to version, change,
improve, etc. While OptionParser might be awesome (and it sounds like it is
for simple stuff), ideally it would be a separate gem.
> Parts of flopp are modelled after how git presents its options which I
found
> very logical.
>
>
>> Can you summarize what makes it different from some of the other
existing
>> tools for this sort of thing -- OptionParse, Highline, Methadone,
GetOpt,
>> Belafonte, Main, GLI, etc....?
Especially what makes it better than those solutions that do exist
already. I am just asking for a bit of advertising. 
I'm not sure I can to fair justice to a comparison of N different
approaches to option parsing. I'm sure they all have their good parts.
Flopp is something that will allow me to make awesome command line
interfaces for the various gems I made, with awesome --help.
- Awesome documentation for nested commands including colours. See the
picture on the github project page for an example.
- Convention over configuration for options to keep your high level
definition as simple as possible.
- Future features planned: command-line auto-completion, detailed help
(perhaps the ability to generate man/markdown pages too).
Some things that I haven't bothered with:
- Options can only have one value and it's not type checked for now (e.g.
this must be an int). Easily fixable but not really useful for me right
now. If you want to do validation, it could be done elsewhere for now.
- The greedy parser is structured in such a way that it doesn't allow you
to have "global" options. For example, what would
command --foo subcommand --foo -- --foo
mean? In Flopp, those are all different options. Other option parsers might
try to resolve this into one option, but for performance and specificity, I
didn't go down this route. That being said, this isn't a bad design, it's
got some benefits too. It might make sense for some options to have global
scope.. but then how do you deal with
command subcommand -- --help
Anyway, it's a work in progress, and I appreciate your feedback and
challenge to explain why it's a good idea.
···
> On Saturday, 23 April 2016, Kirk Haines <wyhaines@gmail.com> wrote: