From: "Brian Schröder" Date: 2005-05-25T18:57:29+09:00 Subject: Re: options parsing: required and conflict On 25/05/05, Kirill Shutemov wrote: > On 5/25/05, nobuyoshi nakada 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? > > I think because the dependency can be arbitrarily complex, so any language would have to be extended until it is turing complete. So it is easier to use ruby in the first place, because no new syntax is introduced. If you want, you can easily write your own mini-language for your special application. Simply create an object descendent from OptionParser that contains your settings as accessors. Include a check routine and call this after parsing I made a small example. Maybe something like this can go into the OptionParser documentation. I think the option parser example at the moment is great but a bit overwhelming. best regards, Brian #!/usr/bin/ruby require 'optparse' class MyOptions < OptionParser attr_accessor :o1, :o2 def initialize(args = ARGV) super(args) self.on("--o1", "Option 1") do self.o1 = true end self.on("--o2", "Option 2") do self.o2 = true end self.parse!(args) self.check end def check raise "Don't specify o1 and o2 at the same time" if self.o1 and self.o2 raise "Specify at least on out of o1 or o2" unless self.o1 or self.o2 end end options = MyOptions.new puts "o1 specified" if options.o1 puts "o2 specified" if options.o2 -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/