From 11ef87461a79877796786af7f0c1eee75ab4f0bf Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 7 Dec 2010 13:31:11 +0000 Subject: [PATCH] * lib/optparse.rb (OptionParser::Officious): separate completion options from --help. [ruby-dev:42690] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- lib/optparse.rb | 30 +++++++++++++++++++----------- misc/rb_optparse.bash | 2 +- misc/rb_optparse.zsh | 2 +- sample/optparse/opttest.rb | 2 +- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 83c6aa4d95..dc7718fe3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Tue Dec 7 22:29:45 2010 Nobuyoshi Nakada +Tue Dec 7 22:31:08 2010 Nobuyoshi Nakada + + * 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. diff --git a/lib/optparse.rb b/lib/optparse.rb index b2c9526598..ef7a0e60bc 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -777,22 +777,30 @@ XXX # --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 diff --git a/misc/rb_optparse.bash b/misc/rb_optparse.bash index 5022442c94..8a59ec2dda 100644 --- a/misc/rb_optparse.bash +++ b/misc/rb_optparse.bash @@ -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 } diff --git a/misc/rb_optparse.zsh b/misc/rb_optparse.zsh index 28f8ede0fe..bd3fc53b2d 100755 --- a/misc/rb_optparse.zsh +++ b/misc/rb_optparse.zsh @@ -16,7 +16,7 @@ generate-complete-function/ruby/optparse () { 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" diff --git a/sample/optparse/opttest.rb b/sample/optparse/opttest.rb index ea3bc5ad46..9247af494f 100755 --- a/sample/optparse/opttest.rb +++ b/sample/optparse/opttest.rb @@ -18,7 +18,7 @@ ARGV.options do 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,