Forum: Ruby Issue with Getopt-declare incorrect parameter specification

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
076787da0775e1600ae30ea00f804809?d=identicon&s=25 Nexos (Guest)
on 2007-03-20 23:21
(Received via mailing list)
Hi,

I'm having a weird problem with the "Getopt-declare" library. I wrote:

require 'rubygems'
require 'Getopt/Declare'

pattern = ".*"
args = Getopt::Declare.new(%q@

  -p <regexp>  some regexp; defaults to ".*" (explanation)
        {
          pattern = regexp
        }
@)

When I run: << ruby script.rb -p '[a-c].*'  >>

, I get the following error:

"Error: incorrect specification of '-p' parameter"

Has someone an explanation for this ?

Thanks in advance,
Frédéric
B74f9ac58c7a0b80d877470198e1a472?d=identicon&s=25 gga (Guest)
on 2007-03-21 08:36
(Received via mailing list)
It seems to work for me with latest 1.22, albeit you should use
$pattern or @pattern.  Otherwise pattern is a local variable to the
block.


require 'rubygems'
require 'Getopt/Declare'

@pattern = ".*"
args = Getopt::Declare.new(%q%
        -p <regexp>       some regexp; defaults to ".*" (explanation)
                                {
                                        @pattern = regexp
                                }
%)

puts "VERSION #{Getopt::Declare::VERSION}"
p args
puts "PATTERN #@pattern"


> try.rb -p hello
VERSION 1.22
-p => "hello"
Unused:
PATTERN .*
076787da0775e1600ae30ea00f804809?d=identicon&s=25 Nexos (Guest)
on 2007-03-21 11:47
(Received via mailing list)
On 21 mar, 08:30, "gga" <GGarram...@aol.com> wrote:
>                                 {
> VERSION 1.22
> -p => "hello"
> Unused:
> PATTERN .*

Thanks for the issue on the variable scope, but the error message
appears when you use a more complex argument value than 'hello',
i.e.

 try.rb -p hello     works fine

but

 try.rb -p '[a-c].*'  gives the error message
B74f9ac58c7a0b80d877470198e1a472?d=identicon&s=25 gga (Guest)
on 2007-03-21 17:11
(Received via mailing list)
On 21 mar, 07:41, "Nexos" <frederic.dela...@gmail.com> wrote:
> > block.
> > %)
> > PATTERN .*
>
> Thanks for the issue on the variable scope, but the error message
> appears when you use a more complex argument value than 'hello',
> i.e.
>
>  try.rb -p hello     works fine
>
> but
>
>  try.rb -p '[a-c].*'  gives the error message

Oh, yes.  This is a bug I recently stumbled upon and has been fixed.

The problem is in Getopt/Declare.rb, around line 668.  There's a:

code << '\b'

Just comment that out.  I'll be making a new release with that fix
soon, but I am also adding a more complex Test::Unit test suite to
catch those sort of errors.
076787da0775e1600ae30ea00f804809?d=identicon&s=25 Nexos (Guest)
on 2007-03-21 20:50
(Received via mailing list)
On Mar 21, 5:08 pm, "gga" <GGarramuno@aol.com> wrote:
> > > require 'rubygems'
> > > puts "VERSION #{Getopt::Declare::VERSION}"
> > Thanks for the issue on the variable scope, but the error message
>
> The problem is inGetopt/Declare.rb, around line 668.  There's a:
>
> code << '\b'
>
> Just comment that out.  I'll be making a new release with that fix
> soon, but I am also adding a more complex Test::Unit test suite to
> catch those sort of errors.

OK.
Just tried it and it worked fine.

Thanks for explanation!

Regards,

Frédéric Delanoy
This topic is locked and can not be replied to.