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 | |
parent | fb8f66cf2339fa4fd99bccc72adb39eab6ba2700 (diff) | |
download | ruby-9d3890ab909277c01c3106a69c3fb19b56cddcc1.tar.gz |
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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/optparse.rb | 8 |
2 files changed, 10 insertions, 3 deletions
@@ -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 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 |