ruby-changes:34808
From: nobu <ko1@a...>
Date: Mon, 21 Jul 2014 15:55:54 +0900 (JST)
Subject: [ruby-changes:34808] nobu:r46891 (trunk): optparse.rb: getopts message improvement
nobu 2014-07-21 15:55:44 +0900 (Mon, 21 Jul 2014) New Revision: 46891 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46891 Log: optparse.rb: getopts message improvement * lib/optparse.rb (getopts): print default values and descriptions in the help message. [fix GH-676] Modified files: trunk/ChangeLog trunk/lib/optparse.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46890) +++ ChangeLog (revision 46891) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jul 21 15:55:42 2014 fuji70 <fujifuji70@g...> + + * 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@8...> * vm_core.h (rb_proc_t): reduce to 64 bytes from 72 on 64-bit Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 46890) +++ lib/optparse.rb (revision 46891) @@ -1495,11 +1495,12 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1495 # # 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 https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1519 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/