Mandatory options with optparse

Discussion in 'Ruby' started by Imobach González Sosa, Aug 29, 2006.

  1. Hi all,

    I was playing with optparse (great stuff ;)) and I didn't see how to check =
    if=20
    a mandatory option have been supplied (note that I say mandatory *option*,=
    =20
    not mandatory *argument*).

    So, if I got the next chunk of code:

    opts =3D OptionParser.new do |opts|
    opts.banner =3D "My silly example"

    opts.on("-m", "--message MESSAGE", "A message to show") do |m|
    options.message =3D m
    end
    end

    I figured out that I'd must check it by my own (if options.message.nil?...)=
    ,=20
    but I only wanna know if there's a "optparse-way".

    Thanks in advance!

    =2D-=20
    _o) Imobach Gonz=E1lez Sosa
    //\ email: imobachgs at banot dot net
    V_/_ jid: osoh at jabberes dot org
    url: http://www.banot.net/~osoh/
    blog: http://devnull.blogs.banot.net
     
    Imobach González Sosa, Aug 29, 2006
    #1
    1. Advertising

  2. Imobach González Sosa

    Guest

    Hi,

    At Wed, 30 Aug 2006 01:06:20 +0900,
    Imobach Gonz=E1lez Sosa wrote in [ruby-talk:211331]:
    > I figured out that I'd must check it by my own (if options.message.nil?..=

    ),=20
    > but I only wanna know if there's a "optparse-way".


    There is no suck way. I had thought about the idea like it
    formerly, but concluded that it's easy to read and write in
    ruby, rather than in mini-DSL.

    --=20
    Nobu Nakada
     
    , Aug 31, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Goodger

    Re: Iterating over optparse options

    David Goodger, Jun 25, 2003, in forum: Python
    Replies:
    0
    Views:
    1,009
    David Goodger
    Jun 25, 2003
  2. Gregory (Grisha) Trubetskoy

    Required options in optparse

    Gregory (Grisha) Trubetskoy, Oct 4, 2003, in forum: Python
    Replies:
    0
    Views:
    428
    Gregory (Grisha) Trubetskoy
    Oct 4, 2003
  3. Steven Bethard
    Replies:
    0
    Views:
    411
    Steven Bethard
    May 10, 2006
  4. Rocky Zhou
    Replies:
    3
    Views:
    332
    Steven Bethard
    Mar 18, 2007
  5. Omari Norman

    Re: optparse - required options

    Omari Norman, Aug 23, 2007, in forum: Python
    Replies:
    2
    Views:
    433
    Steve Holden
    Aug 24, 2007
Loading...

Share This Page