the all-thing | 2010-09-04 17:15:10 -0400 ========================================== Trollop 1.8.1 released ---------------------- Date: June 24, 2008 7:07pm Author: William Morgan Labels: trollop, releases URL: http://all-thing.net/old24.txt Trollop 1.8.1 [1] is out. This is a minor bugfix release, but 1.8, released a few weeks ago but not really advertised, adds new functionality, so I'm describing that here. The new functionality is subcommand support, as seen in things like @git@ and @svn@. This feature is actually trivial to use / implement: you give Trollop a list of stopwords. When it sees one, it stops parsing. The end. That's all you need. Here's how you use it: * Call @Trollop::options@ with your global option specs. Pass it the list of subcommands as the stopwords. It will parse @ARGV@ and stop on the subcommand. * Parse the next word in ARGV as the subcommand, however you wish. @ARGV.shift@ is the traditional choice. * Call @Trollop::options@ again with whatever command-specific options you want. And that's it. Simple eh? It continually amazes me how hard other people make option parsing. I think it's a holdover from their days of using C or Java. Take a look at synopsis for optparse [2] — it's a ridiculous amount of work for something simple. Or better yet, look at the synopsis for CmdParse [3]. Having to make a class for each command is a clunky Java-ism. I'm sorry, but it's true. Subclassing is the one option for specializing code in Java; in Ruby we can be far more sophisticated. Take a look at Ditz's [4] operator.rb [5] for an example of a subcommand DSL. [1] http://trollop.rubyforge.org/ [2] http://docs.huihoo.com/rdoc/ruby/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html [3] http://cmdparse.rubyforge.org/tutorial.html [4] http://ditz.rubyforge.org/ [5] http://gitorious.org/projects/ditz/repos/mainline/blobs/master/lib/operator.rb Replies -------- William, on June 25, 2008 5:49pm: ["| ... and 1.8.2 a day later. Whoops!\n", "| \n"] Brendan, on July 5, 2008 2:35am: ["| \n", "| amen, tell it brother!\n", "| \n"] This delicious text version served up by Whisper .