Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > options parsing: required and conflict

Reply
Thread Tools

options parsing: required and conflict

 
 
Kirill Shutemov
Guest
Posts: n/a
 
      05-25-2005
------=_Part_19699_28028025.1117013576790
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 5/25/05, nobuyoshi nakada <> wrote:
>=20
> Hi,
>=20
> 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.

>=20
> What I disposed is "mini-language" like it.
>=20

Why?

------=_Part_19699_28028025.1117013576790--


 
Reply With Quote
 
 
 
 
Brian Schröder
Guest
Posts: n/a
 
      05-25-2005
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 an=

d
> > > options dependences together.

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

> Why?
>=20
>=20


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 1, 2
def initialize(args =3D ARGV)
super(args)
=20
self.on("--o1", "Option 1") do self.o1 =3D true end
self.on("--o2", "Option 2") do self.o2 =3D true end

self.parse!(args)=20
self.check =20
end
=20
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 =3D MyOptions.new

puts "o1 specified" if options.o1
puts "o2 specified" if options.o2

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


 
Reply With Quote
 
 
 
 
Brian Schröder
Guest
Posts: n/a
 
      05-25-2005
> [snip example]

Should have been

- raise "Specify at least on out of o1 or o2" unless self.o1 or self.o2
+ raise "Specify at least one out of o1 or o2" unless self.o1 or self.o=
2

sorry for this.

best regards,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
css conflict (or html conflict) charles cashion HTML 2 02-18-2009 09:41 PM
difference between *options and options Sijo Kg Ruby 1 01-07-2009 05:51 AM
gcc compiler options for K&R C code Options Utkado C Programming 2 12-18-2008 01:50 PM
Performance issue in multi-level Oracle Object/thin JDBC Options Options jacksu Java 0 10-09-2007 08:21 PM
good compile options for g++ options to enforce good coding Cliff Martin C++ 1 01-31-2007 02:03 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57