On May 27, 1:59 pm, Stefano Crocco <stefano.cro... / alice.it> wrote:
> Alle domenica 27 maggio 2007, Christopher J. Bottaro ha scritto:
>
> > Second, I got it to work by adding :REQUIRED to the on() method call,
> > but that doesn't work as expected:  the argument isn't really
> > "required"; OptionParser does not bomb if the argument is omitted.
>
> From a previous thread on the list
> (http://www.ruby-forum.com/topic/49989#16302), I gather what you want to do
> is impossible with OptionParser (but it may be possible with other libraries:
> I've never used them so I can't tell). To achieve what you mean, you should
> check whether the option was given or not yourself, looking at the variable
> where you stored the options:
>
>   if options.client_ids.empty?
>     puts "You must specify an ID"
>     exit
>   end
>
> > Third, I cannot get a switch to accept multiple arguments.
> > --my_arg 1 2 3
> > I want an array [1, 2, 3].
>
> I don't think you can write a list of that kind, because OptionParser would
> treat every argument as a single option. You can specify more than one
> argument to an option, but you need to separe them with commas, not with
> spaces. If you do that, you can convert the result to an Array by specifying
> it:
>
>   opts.on("--list", Array, "a test list){|a| options.list = a}
>
> I hope this helps
>
> Stefano

Thank you, Stefano, yes it did help.