1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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:
nobu 2014-07-21 06:55:44 +00:00
parent fb8f66cf23
commit 9d3890ab90
2 changed files with 10 additions and 3 deletions

View file

@ -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>
* vm_core.h (rb_proc_t): reduce to 64 bytes from 72 on 64-bit

View file

@ -1495,11 +1495,12 @@ XXX
#
# 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[:b] = "1" # -b1
# # params[:foo] = "1" # --foo
# # params[:bar] = "x" # --bar x
# # params[:zot] = "z" # --zot Z
#
def getopts(*args)
argv = Array === args.first ? args.shift : default_argv
@ -1518,13 +1519,14 @@ XXX
end if single_options
long_options.each do |arg|
arg, desc = arg.split(';', 2)
opt, val = arg.split(':', 2)
if val
result[opt] = val.empty? ? nil : val
define("--#{opt} VAL")
define("--#{opt}=#{result[opt] || "VAL"}", *[desc].compact)
else
result[opt] = false
define("--#{opt}")
define("--#{opt}", *[desc].compact)
end
end