Skip to content

Commit 11ef874

Browse files
committed
* 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
1 parent ff1fb42 commit 11ef874

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
Tue Dec 7 22:29:45 2010 Nobuyoshi Nakada <[email protected]>
1+
Tue Dec 7 22:31:08 2010 Nobuyoshi Nakada <[email protected]>
2+
3+
* lib/optparse.rb (OptionParser::Officious): separate completion
4+
options from --help. [ruby-dev:42690]
25

36
* lib/optparse.rb (OptionParser::Completion#candidate),
47
(OptionParser::Switch#compsys): remove unused variables.

lib/optparse.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -777,22 +777,30 @@ def compsys(to, name = File.basename($0)) # :nodoc:
777777
# --help
778778
# Shows option summary.
779779
#
780-
# --help=complete=WORD
780+
Officious['help'] = proc do |parser|
781+
Switch::NoArgument.new do |arg|
782+
puts parser.help
783+
exit
784+
end
785+
end
786+
787+
# --*-completion-for-bash=WORD
781788
# Shows candidates for command line completion.
782789
#
783-
# --help=zshcomplete[=NAME:FILE]
790+
Officious['*-completion-bash'] = proc do |parser|
791+
Switch::RequiredArgument.new do |arg|
792+
puts parser.candidate(arg)
793+
exit
794+
end
795+
end
796+
797+
#
798+
# --*-completion-zsh[=NAME:FILE]
784799
# Creates zsh completion file.
785800
#
786-
Officious['help'] = proc do |parser|
801+
Officious['*-completion-zsh'] = proc do |parser|
787802
Switch::OptionalArgument.new do |arg|
788-
case arg
789-
when /\Acomplete=(.*)/
790-
puts parser.candidate($1)
791-
when /\Azshcomplete(?:=(.+))?/
792-
parser.compsys(STDOUT, $1)
793-
else
794-
puts parser.help
795-
end
803+
parser.compsys(STDOUT, arg)
796804
exit
797805
end
798806
end

misc/rb_optparse.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# rb_optparse command_using_optparse_2
1212

1313
_rb_optparse() {
14-
COMPREPLY=($("${COMP_WORDS[0]}" --help=complete="${COMP_WORDS[COMP_CWORD]}"))
14+
COMPREPLY=($("${COMP_WORDS[0]}" "--*-completion-bash=${COMP_WORDS[COMP_CWORD]}"))
1515
return 0
1616
}
1717

misc/rb_optparse.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ generate-complete-function/ruby/optparse ()
1616
{
1717
local cmpl="_${1:t}"
1818
mkdir -p "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}"
19-
$1 --help=zshcomplete="${1:t}" > "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl"
19+
$1 "--*-completion-zsh=${1:t}" > "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl"
2020
if [[ $(type -w "$cmpl") == "${cmpl}: function" ]]; then
2121
unfunction "$cmpl"
2222
autoload -U "$cmpl"

sample/optparse/opttest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
opts.on_tail("common options:")
1919

2020
# no argument, shows at tail
21-
opts.on_tail("--usage", "show this message") {puts opts; exit}
21+
opts.on_tail("--help", "show this message") {puts opts; exit}
2222

2323
# mandatory argument
2424
opts.on("-r", "--require=LIBRARY", String,

0 commit comments

Comments
 (0)