Re: optparse question: how to warn of missing positional arguments

Ryan Davis <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>

> On Mar 22, 2019, at 12:48, Artie Ziff <[email protected]> wrote:
> 
> An possible way would be to force the OptionParse.new block parse to fail if ARGV[1] == nil. How to do this properly in Ruby?

Printing the option block arg and exiting non-zero should suffice:

> OptionParser.new do |o|
>   if args.empty? then
>     puts o
>     exit 1
>   end
> end.parse! args

outputs something like:

> Usage: irb [options]

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.