[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

options parsing: required and conflict

Kirill Shutemov

5/11/2005 6:59:00 AM

Can I define options dependencies using OptionParser?
For example: if user defines option --option-a than he has to define
option --option-b or --option-c and mustn't define --option-d and
--option-e.
Is it possible?


12 Answers

Robert Klemme

5/11/2005 8:21:00 AM

0

Kirill Shutemov wrote:
> Can I define options dependencies using OptionParser?
> For example: if user defines option --option-a than he has to define
> option --option-b or --option-c and mustn't define --option-d and
> --option-e.
> Is it possible?

I would check these constraints after all options have been parsed. Nobu
might have a more elegant approach at hand, but I think, you can check
them only after you saw all options because order might differ.

Kind regards

robert

Kirill Shutemov

5/11/2005 8:56:00 AM

0

Is that true, OptionParse has no support of it?


Glenn Parker

5/11/2005 11:47:00 AM

0

Kirill Shutemov wrote:
> Is that true, OptionParse has no support of it?

I don't think OptionParse has any way to express "dependencies" between
options, and that's a good thing. Given the generality of the problem,
there is no way it could do a better job than you would using straight
ruby code.

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoi...


nobu.nokada

5/11/2005 3:13:00 PM

0

Hi,

At Wed, 11 May 2005 20:47:27 +0900,
Glenn Parker wrote in [ruby-talk:142164]:
> I don't think OptionParse has any way to express "dependencies" between
> options, and that's a good thing. Given the generality of the problem,
> there is no way it could do a better job than you would using straight
> ruby code.

I'd had similar idea in the early days, but abandoned it soon.
As those relations could come complicated easily, it didn't
feel worth to design/learn a such "mini-language" again. We
have already the powerful enough language.

--
Nobu Nakada


Kirill Shutemov

5/23/2005 9:11:00 AM

0

> I'd had similar idea in the early days, but abandoned it soon.
> As those relations could come complicated easily, it didn't
> feel worth to design/learn a such "mini-language" again. We
> have already the powerful enough language.

What about add to OptionsParser method 'usage':

opts = OptionParser.new{|opts|
<skip/>
opts.usage("--operation1 [--optional_option] --required_option ARG
[--optional_option2 ARG]")
opts.usage("--operation2 [--optional_option] --required_option2
[--optional_option3 ARG]")
<and_so_on/>
}

I tried to do it by myself, but optparse.rb is too difficult for me :(

nobu.nokada

5/23/2005 11:35:00 PM

0

Hi,

At Mon, 23 May 2005 18:10:50 +0900,
Kirill Shutemov wrote in [ruby-talk:143398]:
> What about add to OptionsParser method 'usage':
>
> opts = OptionParser.new{|opts|
> <skip/>
> opts.usage("--operation1 [--optional_option] --required_option ARG
> [--optional_option2 ARG]")
> opts.usage("--operation2 [--optional_option] --required_option2
> [--optional_option3 ARG]")
> <and_so_on/>
> }

Adding mere messages?

$ ruby -roptparse -e 'ARGV.options{|opt|opt.separator("--foo");opt.parse!}' -- --help
Usage: -e [options]
--foo

--
Nobu Nakada


Eric Hodel

5/23/2005 11:38:00 PM

0


On 23 May 2005, at 02:10, Kirill Shutemov wrote:

> What about add to OptionsParser method 'usage':
>
> opts = OptionParser.new{|opts|
> <skip/>
> opts.usage("--operation1 [--optional_option] --required_option ARG
> [--optional_option2 ARG]")
> opts.usage("--operation2 [--optional_option] --required_option2
> [--optional_option3 ARG]")
> <and_so_on/>
> }
>
> I tried to do it by myself, but optparse.rb is too difficult for me :(

You mean opts.banner and opts.separator?

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



Kirill Shutemov

5/24/2005 9:54:00 AM

0

On 5/24/05, Eric Hodel <drbrain@segment7.net> wrote:
>
>
> You mean opts.banner and opts.separator?
>
No, I mean that such metod can be used for build and usage message and
options dependences together.

Nakada, Nobuyoshi

5/25/2005 2:09:00 AM

0

Hi,

At Tue, 24 May 2005 18:54:14 +0900,
Kirill Shutemov wrote in [ruby-talk:143518]:
> No, I mean that such metod can be used for build and usage message and
> options dependences together.

What I disposed is "mini-language" like it.

--
Nobu Nakada


Kirill Shutemov

5/25/2005 9:33:00 AM

0

On 5/25/05, nobuyoshi nakada <nobuyoshi.nakada@ge.com> wrote:
>
> Hi,
>
> Tue, 24 May 2005 18:54:14 +0900,
> Kirill Shutemov wrote in [ruby-talk:143518]:
> > No, I mean that such metod can be used for build and usage message and
> > options dependences together.
>
> What I disposed is "mini-language" like it.
>
Why?