On 2010-06-13 09:07:31 -0700, John F. said:
delete`, etc., that can be intuitively and cleanly mapped to methods
- ability to be insensitive to option ordering, e.g.
app create --foo quux --bar
should be semantically identical to app create --bar --foo quux
Does that sort of thing exist? I’ve noticed there are some apparently
more powerful alternatives like Thor, which is more of a full-stack
scripting framework, and I’m wondering what else might be useful to
take a look at.
Any and all suggestions would be much appreciated. Thanks!
After recently reviewing the state of the art for Ruby CLI tools myself
as we moved Puppet to a sub-command-based executable structure, I
couldn’t find a single, cohesive library that provides all of these
features. The domain is a full of NIH and wheel reinvention. There also
doesn’t seem to be much thought given to combining multiple tools in a
unix-like fashion (small tools chained together to provide more
complete functionality). They all seem to want to do a bit of
everything but not enough of anything.
OptionParser is convenient because it’s available in the standard
library. There are a number of other option parsing tools but they
(imo) don’t provide significant benefit to offset the cost of an
additional dependency.
As far as subcommands go, there is rake (which can be used as a
stand-alone application DSL), thor (by Yehuda K.), main (by Ara
Howard), the Command code that is a part of the github gem (by Chris
Wanstrath), the Application code that is a part of Puppet and I’m sure
at least a dozen other reimplementations hidden in various gems and
libraries.
I found Rake, Thor and Main gave me too much friction for the type of
CLI tool I was interested in. Option parsing DSLs that were cumbersome,
cryptic error handling and unweildy API design for my use case. That
said, please try them and see if they work for you.
There are probably another dozen tools I haven’t found yet or forgot
didn’t mention. Github queries for “Ruby CLI” and similar return a
staggering number of results. I’d welcome any suggestions for my own
use as well.
Finally I recently wrote a very small sub-command DSL gem[1] in a fit
of my own NIH. It almost certainly doesn’t do what you wantbut you are
welcome to try it. The design goal was to do one thing (subcommands)
and do it well, and to get out of your way and let you use your own
tools for everything else. I would welcome feedback.
[1] GitHub - reinh/commandant: A simple library for writing commands with subcommands (like git)