[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: optparse to include no opt-args, invalid opt,...

Peña, Botp

4/8/2005 8:12:00 AM

nobu.nokada@softhome.net [mailto:nobu.nokada@softhome.net] wrote:

#Peña, Botp wrote in [ruby-talk:136878]:
#> 1. Can optparse capture nil/empty args?
#> 2. Can optparse capture a simple arg?
#> 3. Can optparse capture errors like invalid options or invalid
#> arguments?
#
#No for all, if I get what you mean by "in optparse structure",
#correctly. I guess you're thinking of the case of "capturing
#in separated files/classes" for instance, no?
#
#Maybe worthful. Let me consider for a while.

Hi Nobu, thank you for considering.

In the meantime how do a capture cleanly a simple arg. I can capture invalid
options/args thru error rescue, but a simple non-option arg does not fire an
exception.

eg.

>opsample.rb iwanttocatchthisone

or

>opsample.rb -r okoption iwanttocatchthisone

I'm just asking for any rubyway tip on how to capture it
(iwanttocatchthisone) -other than parsing manually the whole args line.

thanks and kind regards -botp

#
#--
#Nobu Nakada
#



1 Answer

Robert Klemme

4/8/2005 4:54:00 PM

0


""Peña, Botp"" <botp@delmonte-phil.com> schrieb im Newsbeitrag
news:20050408081142.EF4C58403@mx1.delmonte-phil.com...
> nobu.nokada@softhome.net [mailto:nobu.nokada@softhome.net] wrote:
>
> #Peña, Botp wrote in [ruby-talk:136878]:
> #> 1. Can optparse capture nil/empty args?
> #> 2. Can optparse capture a simple arg?
> #> 3. Can optparse capture errors like invalid options or invalid
> #> arguments?
> #
> #No for all, if I get what you mean by "in optparse structure",
> #correctly. I guess you're thinking of the case of "capturing
> #in separated files/classes" for instance, no?
> #
> #Maybe worthful. Let me consider for a while.
>
> Hi Nobu, thank you for considering.
>
> In the meantime how do a capture cleanly a simple arg. I can capture
> invalid
> options/args thru error rescue, but a simple non-option arg does not fire
> an
> exception.
>
> eg.
>
>>opsample.rb iwanttocatchthisone
>
> or
>
>>opsample.rb -r okoption iwanttocatchthisone
>
> I'm just asking for any rubyway tip on how to capture it
> (iwanttocatchthisone) -other than parsing manually the whole args line.
>
> thanks and kind regards -botp

I'm not sure what exactly you're after. The usual approach is that non
option arguments remain in ARGV and can be read from there. You have the
option to either have optparse remove all parsed options and option values
from ARGV or leave them in there. Either way you can get an array with the
remaining command line arguments (in your case that would be a one element
array containing "iwanttocatchthisone").

What exactly is it that you want to do? I don't understand what you gain if
optparse calls a callback block for non option values. Could you please
explain / clarify? Thx.

Kind regards

robert