Usage message in optparse.. summarize method?

Discussion in 'Ruby' started by Jeff Dickens, Dec 1, 2003.

  1. Jeff Dickens

    Jeff Dickens Guest

    I tried your script, and -h doesn't output anything. I'm using ruby 1.8.0.

    Looking through the reference docs for optparse, there seems to be a
    "summarize" method that does what we want.

    But I can't find diddly for examples of more advanced use of optparse. The
    stuff at learning-ruby.com and the FIRSTSTEP.ja.html file that comes with
    the distribution are very basic.

    Does anyone have more examples of using optparase with the summarize method
    or any other advanced examples?

    Thanks.

    Nathaniel Talbott () wrote:
    >> I've been wanting an easy way to output usage info for my
    >> programs that use GetoptLong, without having to duplicate all
    >> the option information; once for the creation of the
    >> GetoptLong object, and again in a help message. ..snip..>Well, you could

    try using optparse...
    >
    > require 'optparse'
    >
    > ARGV.options do |options|
    > options.on('-d', '--date=DATE', String, 'specify a date'){|v| puts

    "Date
    >#{v} passed"}
    > options.on('-q', '--quiet', 'be verry quiet'){puts "OK, I'm being very,
    >very, very quiet... can't you tell?"}
    > options.on_tail('-h', '--help', 'Print this help information'){puts
    >options; exit}
    > options.parse!
    > end
    >
    >I believe that's approximately equal to what you posted. I've only just
    >begun using optparse, but it seems quite powerful and easy to use.
    >
    >HTH,
    >
    >
    >Nathaniel
    >
    ><:((><
     
    Jeff Dickens, Dec 1, 2003
    #1
    1. Advertising

  2. On Nov 30, 2003, at 21:37, Jeff Dickens wrote:

    > I tried your script, and -h doesn't output anything. I'm using ruby
    > 1.8.0.


    jacob:~/tmp ntalbott$ ruby -v t.rb -h
    ruby 1.8.1 (2003-11-30) [powerpc-darwin]
    Usage: t [options]
    -d, --date=DATE specify a date
    -q, --quiet be verry quiet
    -h, --help Print this help information
    jacob:~/tmp ntalbott$ cat t.rb
    require 'optparse'

    ARGV.options do |options|
    options.on('-d', '--date=DATE', String, 'specify a date'){|v| puts
    "Date #{v} passed"}
    options.on('-q', '--quiet', 'be verry quiet') do
    puts "OK, I'm being very, very, very quiet... can't you tell?"
    end
    options.on_tail('-h', '--help', 'Print this help information'){puts
    options; exit}
    options.parse!
    end

    Not sure why you had trouble; can you give more details?


    > But I can't find diddly for examples of more advanced use of optparse.
    > The
    > stuff at learning-ruby.com and the FIRSTSTEP.ja.html file that comes
    > with
    > the distribution are very basic.


    I've used http://docs.meg.nu/local-docs/ruby/optparse/optparse.html a
    lot; it has an extensive example at the end.

    HTH,


    Nathaniel

    <:((><
     
    Nathaniel Talbott, Dec 1, 2003
    #2
    1. Advertising

  3. Jeff Dickens

    Guest

    Hi,

    At Mon, 1 Dec 2003 12:07:34 +0900,
    Nathaniel Talbott wrote:
    > ARGV.options do |options|
    > options.on('-d', '--date=DATE', String, 'specify a date'){|v| puts "Date #{v} passed"}


    If you really want to accept only dates, you can use Date
    instead of String here, with requiring 'optparse/date'.

    --
    Nobu Nakada
     
    , Dec 1, 2003
    #3
  4. On Dec 1, 2003, at 02:28, wrote:

    > Hi,
    >
    > At Mon, 1 Dec 2003 12:07:34 +0900,
    > Nathaniel Talbott wrote:
    >> ARGV.options do |options|
    >> options.on('-d', '--date=DATE', String, 'specify a date'){|v|
    >> puts "Date #{v} passed"}

    >
    > If you really want to accept only dates, you can use Date
    > instead of String here, with requiring 'optparse/date'.


    Wow. Very cool.

    Thanks for optparse - I've found it to be extremely useful. It makes it
    so easy to provide command-line usage information for scripts that it's
    almost criminal not to. Not to mention that it also makes it a cinch to
    process command-line options.


    Nathaniel

    <:((><
     
    Nathaniel Talbott, Dec 1, 2003
    #4
  5. Jeff Dickens

    Jeff Dickens Guest

    It was a very ruby nuby mistake on my part.. I cut and pasted and forgot to
    remove the extra carriage returns thereby introduced.

    Works fine now. Thanks.

    And btw, what's your signoff "HTH" mean ?


    "Nathaniel Talbott" <> wrote in message
    news:...
    > On Nov 30, 2003, at 21:37, Jeff Dickens wrote:
    >
    > > I tried your script, and -h doesn't output anything. I'm using ruby
    > > 1.8.0.

    >
    > jacob:~/tmp ntalbott$ ruby -v t.rb -h
    > ruby 1.8.1 (2003-11-30) [powerpc-darwin]
    > Usage: t [options]
    > -d, --date=DATE specify a date
    > -q, --quiet be verry quiet
    > -h, --help Print this help information
    > jacob:~/tmp ntalbott$ cat t.rb
    > require 'optparse'
    >
    > ARGV.options do |options|
    > options.on('-d', '--date=DATE', String, 'specify a date'){|v| puts
    > "Date #{v} passed"}
    > options.on('-q', '--quiet', 'be verry quiet') do
    > puts "OK, I'm being very, very, very quiet... can't you tell?"
    > end
    > options.on_tail('-h', '--help', 'Print this help information'){puts
    > options; exit}
    > options.parse!
    > end
    >
    > Not sure why you had trouble; can you give more details?
    >
    >
    > > But I can't find diddly for examples of more advanced use of optparse.
    > > The
    > > stuff at learning-ruby.com and the FIRSTSTEP.ja.html file that comes
    > > with
    > > the distribution are very basic.

    >
    > I've used http://docs.meg.nu/local-docs/ruby/optparse/optparse.html a
    > lot; it has an extensive example at the end.
    >
    > HTH,
    >
    >
    > Nathaniel
    >
    > <:((><
    >
    >
    >
     
    Jeff Dickens, Dec 1, 2003
    #5
  6. On Dec 1, 2003, at 13:02, Jeff Dickens wrote:

    > It was a very ruby nuby mistake on my part.. I cut and pasted and
    > forgot to
    > remove the extra carriage returns thereby introduced.
    >
    > Works fine now. Thanks.


    Great!


    > And btw, what's your signoff "HTH" mean ?


    Just an abbrev for "Hope That Helps" :)


    Nathaniel

    <:((><
     
    Nathaniel Talbott, Dec 1, 2003
    #6
    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. bastardx

    summarize bytes

    bastardx, Jun 7, 2005, in forum: Perl
    Replies:
    7
    Views:
    2,801
    thoomas
    Jun 16, 2005
  2. robin

    summarize text

    robin, May 29, 2006, in forum: Python
    Replies:
    4
    Views:
    1,889
    Lawrence D'Oliveiro
    Jun 5, 2006
  3. =?ISO-8859-1?Q?Count_L=E1szl=F3_de_Alm=E1sy?=

    optparse: add trailing text in help message?

    =?ISO-8859-1?Q?Count_L=E1szl=F3_de_Alm=E1sy?=, Oct 13, 2006, in forum: Python
    Replies:
    4
    Views:
    581
    Steven Bethard
    Oct 15, 2006
  4. DeMarcus
    Replies:
    13
    Views:
    608
    BGB / cr88192
    Sep 14, 2010
  5. hhw
    Replies:
    0
    Views:
    104
Loading...

Share This Page