From: John Feminella on 13 Jun 2010 12:07 I am starting construction on a somewhat complicated internal application whose primary interface will be the command line. In the past, for similar projects, I've just used OptionParser, but I think I need something a little beefier. Specifically, I think I need these features: * colorized output * sensible option parsing * sensible enumeration of options for help output * support for `git`-like subcommands, e.g., `app create`, `app 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!
From: Intransition on 13 Jun 2010 15:43 On Jun 13, 12:07 pm, John Feminella <jo...(a)distb.net> wrote: > I am starting construction on a somewhat complicated internal > application whose primary interface will be the command line. In the > past, for similar projects, I've just used OptionParser, but I think I > need something a little beefier. Specifically, I think I need these > features: > > * colorized output > * sensible option parsing > * sensible enumeration of options for help output > * support for `git`-like subcommands, e.g., `app create`, `app > 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! OptionParser generally works fine --even for the items you mention. To handle subcommands just pop off the top of ARGV before parsing (or for more advanced use, find the first non-option item). The order of options is not an issue, and help is pretty easy since OptionPaser responds to #to_s. Running that through a colorizing filter shouldn't be too hard. For color try http://rubyworks.github.com/ansi. There are other options out there though, check out HighLine and Oyster for instance.
From: Rein Henrichs on 13 Jun 2010 21:53 On 2010-06-13 09:07:31 -0700, John Feminella said: > I am starting construction on a somewhat complicated internal > application whose primary interface will be the command line. In the > past, for similar projects, I've just used OptionParser, but I think I > need something a little beefier. Specifically, I think I need these > features: > > * colorized output > * sensible option parsing > * sensible enumeration of options for help output > * support for `git`-like subcommands, e.g., `app create`, `app > 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 Katz), 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] http://github.com/reinh/commandant -- Rein Henrichs http://puppetlabs.com http://reinh.com
From: Brian Candler on 18 Jun 2010 04:13 Rein Henrichs wrote: > There are probably another dozen tools I haven't found yet or forgot > didn't mention. There's one I can never remember the name of, but is something to do with prostitutes. Oh yes, it's "trollop". Examples at http://trollop.rubyforge.org/ suggest that subcommands are supported. -- Posted via http://www.ruby-forum.com/.
From: R.. Kumar on 18 Jun 2010 05:17 John Feminella wrote: > > 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! There's also visionmedia's commander http://github.com/visionmedia/commander. I've played with it a bit, but not started working on it. I've started converting some shell-scripts to ruby, and i've rolled my first one using optionparser. I may try commander for the second one. But I am afraid of a large code base, and it getting broken at some stage. For the ease of some option parsing and a few more tiny goodies, I can;t have my entire app dependent on some large code base. My current apps manipulate files largely using "sed", "grep", "cut" and some other unix commands. So the meat of my programs is still not served by these frameworks. I once tried Thor and liked it. But its written by Y Katz who is into Rails currently. So i don't know if it's being maintained (if you run into issues). I;ve been bitten earlier using a gem written by a high profile programmer who was too involved elsewhere to fix a bug in his gem or even reply. :-( -- Posted via http://www.ruby-forum.com/.
|
Next
|
Last
Pages: 1 2 3 Prev: 2010 FIFA World Cup Real Madrid Club football jersey Next: Do I overuse class methods? |