Forum: Ruby-core [ruby-trunk - Bug #7537][Open] OptionParser treats negative digits as options

Posted by prijutme4ty (Ilya Vorontsov) (Guest)
on 2012-12-09 11:00
(Received via mailing list)
Issue #7537 has been reported by prijutme4ty (Ilya Vorontsov).

----------------------------------------
Bug #7537: OptionParser treats negative digits as options
https://bugs.ruby-lang.org/issues/7537

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3(p0, p327 both)


Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a 
number

OptionParser.new {|opts|
  opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v|  puts "P-value: 
#{v}" }
}.parse!

`ruby my_test.rb -p -1` works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
  opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v|  puts 
"P-value: #{v}" }
}.parse!

`ruby my_test.rb -p -1` fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
  opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

`ruby my_test.rb -1` also fails with "Invalid option -1"
Posted by prijutme4ty (Ilya Vorontsov) (Guest)
on 2012-12-09 15:13
(Received via mailing list)
Issue #7537 has been updated by prijutme4ty (Ilya Vorontsov).


In my opinion, negative numbers shouldn't be treated as option keys 
unless it was explicitly specified. In other cases them should be 
treated as usual parameters.
----------------------------------------
Bug #7537: OptionParser treats negative digits as options
https://bugs.ruby-lang.org/issues/7537#change-34562

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3(p0, p327 both)


Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a 
number

OptionParser.new {|opts|
  opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v|  puts "P-value: 
#{v}" }
}.parse!

`ruby my_test.rb -p -1` works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
  opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v|  puts 
"P-value: #{v}" }
}.parse!

`ruby my_test.rb -p -1` fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
  opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

`ruby my_test.rb -1` also fails with "Invalid option -1"
Posted by zzak (Zachary Scott) (Guest)
on 2012-12-10 05:48
(Received via mailing list)
Issue #7537 has been updated by zzak (Zachary Scott).

Category set to lib
Assignee set to nobu (Nobuyoshi Nakada)


----------------------------------------
Bug #7537: OptionParser treats negative digits as options
https://bugs.ruby-lang.org/issues/7537#change-34576

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: lib
Target version:
ruby -v: 1.9.3(p0, p327 both)


Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a 
number

OptionParser.new {|opts|
  opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v|  puts "P-value: 
#{v}" }
}.parse!

`ruby my_test.rb -p -1` works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
  opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v|  puts 
"P-value: #{v}" }
}.parse!

`ruby my_test.rb -p -1` fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
  opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

`ruby my_test.rb -1` also fails with "Invalid option -1"
Posted by usa (Usaku NAKAMURA) (Guest)
on 2012-12-21 14:24
(Received via mailing list)
Issue #7537 has been updated by usa (Usaku NAKAMURA).

Status changed from Open to Assigned


----------------------------------------
Bug #7537: OptionParser treats negative digits as options
https://bugs.ruby-lang.org/issues/7537#change-34955

Author: prijutme4ty (Ilya Vorontsov)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: lib
Target version:
ruby -v: 1.9.3(p0, p327 both)


Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a 
number

OptionParser.new {|opts|
  opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v|  puts "P-value: 
#{v}" }
}.parse!

`ruby my_test.rb -p -1` works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
  opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v|  puts 
"P-value: #{v}" }
}.parse!

`ruby my_test.rb -p -1` fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
  opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

`ruby my_test.rb -1` also fails with "Invalid option -1"
Posted by prijutme4ty (Ilya Vorontsov) (Guest)
on 2013-03-18 13:53
(Received via mailing list)
Issue #7537 has been updated by prijutme4ty (Ilya Vorontsov).


Sent a pull-request. https://github.com/ruby/ruby/pull/259
I've made changes the same way as python do -- 
http://docs.python.org/dev/library/argparse.html#a...
This patch introduces one possible (but not very serious and very rare) 
incompatibility: if one already uses explicitly defined negative-digit 
option such as '-1' and also uses an option with optional argument '-p 
[ARG]' and runs a command with options '-p -1' then before patch it'll 
be treated as two different options '-p', '-1' and after patch they are 
treated as an option '-p' with value '-1'.
If one meets this problem, he can use option declaration with equal 
sign: '-p=[ARG]' or just change places of arguments and run his program 
with options '-1 -p'.
But I suppose not too many people use explicitly defined numeric options 
and even less people use optional argument with them in such order (may 
be even nobody use it such a way).
----------------------------------------
Bug #7537: OptionParser treats negative digits as options
https://bugs.ruby-lang.org/issues/7537#change-37695

Author: prijutme4ty (Ilya Vorontsov)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: lib
Target version:
ruby -v: 1.9.3(p0, p327 both)


Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a 
number

OptionParser.new {|opts|
  opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v|  puts "P-value: 
#{v}" }
}.parse!

`ruby my_test.rb -p -1` works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
  opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v|  puts 
"P-value: #{v}" }
}.parse!

`ruby my_test.rb -p -1` fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
  opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

`ruby my_test.rb -1` also fails with "Invalid option -1"
Posted by zzak (Zachary Scott) (Guest)
on 2013-04-05 04:38
(Received via mailing list)
Issue #7537 has been updated by zzak (Zachary Scott).

File 259.patch added

I've attached the patch from the associated pull request.
----------------------------------------
Bug #7537: OptionParser treats negative digits as options
https://bugs.ruby-lang.org/issues/7537#change-38246

Author: prijutme4ty (Ilya Vorontsov)
Status: Assigned
Priority: Normal
Assignee: nobu (Nobuyoshi Nakada)
Category: lib
Target version:
ruby -v: 1.9.3(p0, p327 both)


Is it intentional that negative digits are treated as options?
If I use negative digit as an argument of an option, it is treated as a 
number

OptionParser.new {|opts|
  opts.on('-p','--pvalue VAL', Integer, 'P-value') {|v|  puts "P-value: 
#{v}" }
}.parse!

`ruby my_test.rb -p -1` works normally

But if I use it as optional argument of an option:

OptionParser.new {|opts|
  opts.on('-p','--pvalue [VAL]', Integer, 'P-value') {|v|  puts 
"P-value: #{v}" }
}.parse!

`ruby my_test.rb -p -1` fails with "Invalid option -1"

Also I can't use it as non-optional argument

OptionParser.new {|opts|
  opts.on('-n', 'no Pvalue argument, other arguments only') {}
}.parse!
puts ARGV

`ruby my_test.rb -1` also fails with "Invalid option -1"
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.