ruby-changes:18100
From: nobu <ko1@a...>
Date: Tue, 7 Dec 2010 22:37:55 +0900 (JST)
Subject: [ruby-changes:18100] Ruby:r30121 (trunk): * lib/optparse.rb (OptionParser::Officious): separate completion
nobu 2010-12-07 22:31:11 +0900 (Tue, 07 Dec 2010) New Revision: 30121 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30121 Log: * lib/optparse.rb (OptionParser::Officious): separate completion options from --help. [ruby-dev:42690] Modified files: trunk/ChangeLog trunk/lib/optparse.rb trunk/misc/rb_optparse.bash trunk/misc/rb_optparse.zsh trunk/sample/optparse/opttest.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30120) +++ ChangeLog (revision 30121) @@ -1,5 +1,8 @@ -Tue Dec 7 22:29:45 2010 Nobuyoshi Nakada <nobu@r...> +Tue Dec 7 22:31:08 2010 Nobuyoshi Nakada <nobu@r...> + * lib/optparse.rb (OptionParser::Officious): separate completion + options from --help. [ruby-dev:42690] + * lib/optparse.rb (OptionParser::Completion#candidate), (OptionParser::Switch#compsys): remove unused variables. Index: misc/rb_optparse.zsh =================================================================== --- misc/rb_optparse.zsh (revision 30120) +++ misc/rb_optparse.zsh (revision 30121) @@ -16,7 +16,7 @@ { local cmpl="_${1:t}" mkdir -p "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}" - $1 --help=zshcomplete="${1:t}" > "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl" + $1 "--*-completion-zsh=${1:t}" > "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl" if [[ $(type -w "$cmpl") == "${cmpl}: function" ]]; then unfunction "$cmpl" autoload -U "$cmpl" Index: misc/rb_optparse.bash =================================================================== --- misc/rb_optparse.bash (revision 30120) +++ misc/rb_optparse.bash (revision 30121) @@ -11,7 +11,7 @@ # rb_optparse command_using_optparse_2 _rb_optparse() { - COMPREPLY=($("${COMP_WORDS[0]}" --help=complete="${COMP_WORDS[COMP_CWORD]}")) + COMPREPLY=($("${COMP_WORDS[0]}" "--*-completion-bash=${COMP_WORDS[COMP_CWORD]}")) return 0 } Index: sample/optparse/opttest.rb =================================================================== --- sample/optparse/opttest.rb (revision 30120) +++ sample/optparse/opttest.rb (revision 30121) @@ -18,7 +18,7 @@ opts.on_tail("common options:") # no argument, shows at tail - opts.on_tail("--usage", "show this message") {puts opts; exit} + opts.on_tail("--help", "show this message") {puts opts; exit} # mandatory argument opts.on("-r", "--require=LIBRARY", String, Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 30120) +++ lib/optparse.rb (revision 30121) @@ -777,22 +777,30 @@ # --help # Shows option summary. # - # --help=complete=WORD + Officious['help'] = proc do |parser| + Switch::NoArgument.new do |arg| + puts parser.help + exit + end + end + + # --*-completion-for-bash=WORD # Shows candidates for command line completion. # - # --help=zshcomplete[=NAME:FILE] + Officious['*-completion-bash'] = proc do |parser| + Switch::RequiredArgument.new do |arg| + puts parser.candidate(arg) + exit + end + end + + # + # --*-completion-zsh[=NAME:FILE] # Creates zsh completion file. # - Officious['help'] = proc do |parser| + Officious['*-completion-zsh'] = proc do |parser| Switch::OptionalArgument.new do |arg| - case arg - when /\Acomplete=(.*)/ - puts parser.candidate($1) - when /\Azshcomplete(?:=(.+))?/ - parser.compsys(STDOUT, $1) - else - puts parser.help - end + parser.compsys(STDOUT, arg) exit end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/