optparse.rb: getopts message improvement
* lib/optparse.rb (getopts): print default values and descriptions in the help message. [fix GH-676] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fb8f66cf23
commit
9d3890ab90
@ -1,3 +1,8 @@
|
|||||||
|
Mon Jul 21 15:55:42 2014 fuji70 <fujifuji70@gmail.com>
|
||||||
|
|
||||||
|
* lib/optparse.rb (getopts): print default values and descriptions
|
||||||
|
in the help message. [fix GH-676]
|
||||||
|
|
||||||
Sun Jul 20 14:26:27 2014 Eric Wong <e@80x24.org>
|
Sun Jul 20 14:26:27 2014 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
* vm_core.h (rb_proc_t): reduce to 64 bytes from 72 on 64-bit
|
* vm_core.h (rb_proc_t): reduce to 64 bytes from 72 on 64-bit
|
||||||
|
@ -1495,11 +1495,12 @@ XXX
|
|||||||
#
|
#
|
||||||
# Wrapper method for getopts.rb.
|
# Wrapper method for getopts.rb.
|
||||||
#
|
#
|
||||||
# params = ARGV.getopts("ab:", "foo", "bar:")
|
# params = ARGV.getopts("ab:", "foo", "bar:", "zot:Z;zot option)
|
||||||
# # params[:a] = true # -a
|
# # params[:a] = true # -a
|
||||||
# # params[:b] = "1" # -b1
|
# # params[:b] = "1" # -b1
|
||||||
# # params[:foo] = "1" # --foo
|
# # params[:foo] = "1" # --foo
|
||||||
# # params[:bar] = "x" # --bar x
|
# # params[:bar] = "x" # --bar x
|
||||||
|
# # params[:zot] = "z" # --zot Z
|
||||||
#
|
#
|
||||||
def getopts(*args)
|
def getopts(*args)
|
||||||
argv = Array === args.first ? args.shift : default_argv
|
argv = Array === args.first ? args.shift : default_argv
|
||||||
@ -1518,13 +1519,14 @@ XXX
|
|||||||
end if single_options
|
end if single_options
|
||||||
|
|
||||||
long_options.each do |arg|
|
long_options.each do |arg|
|
||||||
|
arg, desc = arg.split(';', 2)
|
||||||
opt, val = arg.split(':', 2)
|
opt, val = arg.split(':', 2)
|
||||||
if val
|
if val
|
||||||
result[opt] = val.empty? ? nil : val
|
result[opt] = val.empty? ? nil : val
|
||||||
define("--#{opt} VAL")
|
define("--#{opt}=#{result[opt] || "VAL"}", *[desc].compact)
|
||||||
else
|
else
|
||||||
result[opt] = false
|
result[opt] = false
|
||||||
define("--#{opt}")
|
define("--#{opt}", *[desc].compact)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user