mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
ff1fb42734
commit
11ef87461a
5 changed files with 26 additions and 15 deletions
|
@ -1,4 +1,7 @@
|
|||
Tue Dec 7 22:29:45 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Tue Dec 7 22:31:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue