[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: optparser question
From: Robert Klemme <shortcutter () googlemail ! com>
Date: 2010-06-30 12:34:21
Message-ID: AANLkTil9QmO3x_IYoIhZUW5RRStEknAdLINupER-cWHC () mail ! gmail ! com
[Download RAW message or body]
2010/6/30 Zhao Yi <youhaodeyi@gmail.com>:
> I am using optparser to parse arguments.How can I set a mandatory
> option? If user doesn't specify this option, parse() method should throw
> an error message.
There are no mandatory options - after all, they are _options_. You
can only have mandatory arguments to options:
http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
You need an extra flag which you set when the option is seen. Then you
can throw or do whatever after #parse has finished.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic