From: Brett Williams Date: 2004-08-24T05:25:47+09:00 Subject: optparse [feature request: subcommand support] After 2 1/2 years, it looks as if I'll finally get off of my old CVS snapshot of ruby 1.7.2 (phew!). As a result, I can now look at using a lot of the huge new standard library. optparse is one I'm particularly interested in. Earlier this year I saw it, and since I couldn't use it, I copied some of its features as it seems to be much better than getoptlong. I'm missing some of them which I want, however (type coercion and keyword completion principally). I'd like to convert my stuff over to the OptionParser when 1.8.1 gets rolled out. I do have one feature that optparse appears to lack, and I'm just wondering if there is any interest in it (here's the feature request). The feature is the ability to do what I call CVS-style subcommands, i.e.: vor-lord:scaf_flow/scaf_flow> cvs help Unknown command: `help' CVS commands are: add Add a new file/directory to the repository admin Administration front end for rcs annotate Show last revision where each line was modified checkout Checkout sources for editing commit Check files into the repository .... I then want to be able to have options that are local to a subcommand, as well as global options, i.e.: Usage: cvs [cvs-options] command [command-options-and-arguments] The implementation of this should be quite trivial. (In my own implementation I just have a hash of objects, one of which is a default object, which is operated on when no name is given. That said, I don't know much about the structure of OptionParser and it may not lend itself to an easy modification such as this). For example, one could do something like: opts.on('-r', '--recursive', 'operate recursively') do ... end opts.on_cmd('admin', '-r', '--remove', 'removes something') do |arg| ... end As such things can even be reused (as in the above example, -r can be global or local, or both): foo -r admin -r '*Helper*' There would need to be a little bit of smarts in the usage string generator, but by and large it doesn't seem to be too difficult. Does this sound reasonable? Is there anyone else who'd like this kind of thing? Or am I on my own? Thanks for reading this far. I didn't find anything related to this in a search of the archives (hopefully I didn't miss anything).