From: Stephan Wehner Date: 2009-05-29T01:38:38+09:00 Subject: Re: OptionParser: unexpected behaviour with -help Eric Hodel wrote: > On May 23, 2009, at 21:58, Stephan Wehner wrote: > >> I don't think that '-help' should be treated the same as '-h -ex lp' >> or >> '-h --ex lp'. In particular, '-help' may be a misspelling of the >> common '--help' option. Am I doing something wrong? Is there a way to >> avoid this? > > When you use - instead of -- you invoke short-option-parsing like: > > $ ruby -dvrubygems -e 'raise rescue nil' > ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] > Exception `LoadError' at /Library/Ruby/Site/1.8/rubygems.rb:1106 - no > such file to load -- rubygems/defaults/operating_system > Exception `LoadError' at /Library/Ruby/Site/1.8/rubygems/ > config_file.rb:35 - no such file to load -- Win32API > Exception `RuntimeError' at -e:1 - > $ > > Which is equivalent to: > > ruby -d -v -r ubygems -e 'raise rescue nil' There is some precedence for disabling this kind of command line parsing, see http://jargs.sourceforge.net/doc/api/jargs/gnu/CmdLineParser.NotFlagException.html http://tinyurl.com/notflagexception Quote: public static class CmdLineParser.NotFlagException extends CmdLineParser.UnknownOptionException Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one or more requires a value. getMessage() returns an english human-readable error string. End quote This looks like a useful option to support. Stephan -- Posted via http://www.ruby-forum.com/.