Robert Klemme wrote: > > I would modify that approach because it has the drawback of wasting CPU > cycles creating all the unnecessary OptionParsers for subcommands that > are not found in ARGV. Rather, I'd do something more lazy, e.g. > > global = OptionParser.new do |opts| > # ... > end > > subcommands = { > 'foo' => lambda {|argv| OptionParser.new do |opts| > # ... > end.parse! argv}, > # ... > 'baz' => lambda {|argv| OptionParser.new do |opts| > # ... > end.parse! argv}, > } > > global.order! > subcommands[ARGV.shift][ARGV] > > Of course you can also make "subcommands" a method which figures what to > return based on the argument (command name). > > Kind regards > > robert I have actually isolated this into a seperate module with a method named "command" which creates the subcommand. It also takes care of : prog help command which trollop does not to my knowledge. It also prints out the subcommands with their descriptions when typing help or --help just as git does (which trollop does not.) http://gist.github.com/445992 I will look into your feedback about lazy creation and update the same. Could you have a quick look at the gist attached since my ruby is quite newbie level. -- Posted via http://www.ruby-forum.com/.