From: Vincent Fourmond Date: 2006-11-15T18:37:49+09:00 Subject: [was parsing unknown options] OptionParser documentation improvements Robert Klemme wrote: > On 14.11.2006 18:19, ara.t.howard@noaa.gov wrote: >> On Tue, 14 Nov 2006, Stefano Crocco wrote: >> >>> Thanks for the answers. I decided to take an approach similar to >>> building my own parser, but keeping my two steps approach: >>> - first: >>> >>> ARGV.each_with_index do |s, i| >>> plugin=args[i+1] if s=='-p' or s=='--plugin' or s=~/-\w*p/ >>> end >>> >>> (this should take care of the three possible formats: short option, long >>> option and several short options together, such as -abp plugin >>> >>> - load the plugin >>> - use OptionParser to rescan the options >>> >>> I'm still working on how to communicate the options recognized by the >>> plugin to the main program. >>> >>> Stefano >> >> OptionParser already handles unknown options: >> >> begin >> option_parser.parse! argv >> rescue OptionParser::InvalidOption => e >> # preverve unknown options >> e.recover argv >> end > > Thanks! Learn something new every day. I believe OptionParser to be an > excellent piece of software - actually this short example is just > another confirmation for that. But I always found that documentation of > OptionParser was a bit weak. Did I miss anything? Clearly the docs on > ruby-doc.org are rudimentary. Is there anyone that knows OptionParser > intimately and is willing to write up some documentation or at least add > some more examples to doc of class OptionParser that demonstrate > additional funcationality? It might be sufficient to just collect > working pieces of OptionParser code from the community, massage it a bit > and place it into the default docs. I would greatly appreciate that - > and probably others, too. What do you think? I think that it would be a great idea. Personnaly, I always found that looking at the code, documentation and trying was enough, but with appropriate examples, that would be a lot easier. If the current maintainers of OptionParser are reading this, that would be nice to tell us how we could contribute to this ? Would it make sense to put that documentation on a personal page, waiting to be included upstream ? I'd be willing to do that, if anyone wants to contribute. Cheers ! Vince -- Vincent Fourmond, PhD student http://vincent.fourmond.neuf.fr/