diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-21 06:55:44 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-21 06:55:44 +0000 |
commit | 9d3890ab909277c01c3106a69c3fb19b56cddcc1 (patch) | |
tree | bd595755c5b8ad9a5f96f9a5d1940370bb95e3c3 /lib/optparse.rb | |
parent | fb8f66cf2339fa4fd99bccc72adb39eab6ba2700 (diff) |
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
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r-- | lib/optparse.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index 6d12064b5d..4ec891e3ae 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -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 |