GetoptLong Accessing the values with out looping

Just ARGV, I'm afraid. I suppose you could push args onto ARGV directly
as a workaround.

May I ask when you would want to parse an arbitrary array? I'm curious.

Oh, and when I said, "Yes, it sucks", I was referring to getoptlong in
the stdlib, not your code in particular. Just thought I should clarify
that. :slight_smile:

Regards,

Dan

This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

路路路

-----Original Message-----
From: ara.t.howard@noaa.gov [mailto:ara.t.howard@noaa.gov]
Sent: Tuesday, May 16, 2006 8:46 AM
To: ruby-talk ML
Subject: Re: GetoptLong Accessing the values with out looping

On Tue, 16 May 2006, Berger, Daniel wrote:

>> -----Original Message-----
>> From: Paul D. Kraus [mailto:paul.kraus@gmail.com]
>> Sent: Tuesday, May 16, 2006 8:13 AM
>> To: ruby-talk ML
>> Subject: Re: GetoptLong Accessing the values with out looping
>>
>>
>>>
>>> opts = {} and gl.each{|k,v| opts[k.delete('-')] = v}
>>>
>> Makes perfect sense in this example you are still looping
through the
>> options. All though this is better on the eyes.
>>
>> I was hoping that the instance of getoptlong had some kind
of method
>> to get the value of one of the command line options.
>>
>> Paul
>
> Yes, it sucks. That's why I wrote the 'getopt' package.
>
> gem install getopt :slight_smile:
>
> require 'getopt/long'
> include Getopt
>
> opts = Getopt::Long.new(['-d', '--date', REQUIRED])
>
> if opts['d']
> # ...
> end
>
> Regards,
>
> Dan

nice dan. i've been using optparse for all my stuff but it's
usage is a bit obtuse. perhaps i'll switch... does it
support parsing arbitrary arrays or only ARGV?

regards.

-a

Just ARGV, I'm afraid. I suppose you could push args onto ARGV directly as
a workaround.

May I ask when you would want to parse an arbitrary array? I'm curious.

most of my standalone production code looks like this

   ~ > cat foo

   module Foo
     class Main
       ...
     end
   end

   Foo::Main.run(ARGV, ENV) if __FILE__ == $0

that way foo runs as a script. however the code can be re-used in this way
too

   ~ > cat bar

   require 'foo'

   module Bar
     class Main < Foo::Main
       argv << '--foo-option=42'
       env['foo_env'] = 42
       super(argv, env)
     end
   end

   Bar::Main.run(ARGV, ENV) if __FILE__ == $0

or

   foo = Foo::Main.new '--key=val --k2-v2'

etc.

basically i re-use top-level code as libs sometimes and then it's important
that two bits of code aren't fighting over ARGV/ENV.

Oh, and when I said, "Yes, it sucks", I was referring to getoptlong in
the stdlib, not your code in particular. Just thought I should clarify
that. :slight_smile:

either way - no offense taken!

cheers.

-a

路路路

On Tue, 16 May 2006, Berger, Daniel wrote:
--
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama

Easier to write unit tests for, maybe.

-- Daniel

路路路

On May 16, 2006, at 4:51 PM, Berger, Daniel wrote:

Just ARGV, I'm afraid. I suppose you could push args onto ARGV directly
as a workaround.

May I ask when you would want to parse an arbitrary array? I'm curious.