--- a/docs/changelog.rst Mon Dec 06 23:45:14 2010 +0100
+++ b/docs/changelog.rst Tue Dec 07 12:26:36 2010 +0100
@@ -1,6 +1,12 @@
Changelog
---------
+1.1 (2010.12.07)
+~~~~~~~~~~~~~~~~
+
+ - _completion was failing to work when global options were supplied to command
+ dispatcher
+
1.0 (2010.12.06)
~~~~~~~~~~~~~~~~
--- a/opster.py Mon Dec 06 23:45:14 2010 +0100
+++ b/opster.py Tue Dec 07 12:26:36 2010 +0100
@@ -6,7 +6,7 @@
from itertools import imap
__all__ = ['command', 'dispatch']
-__version__ = '1.0'
+__version__ = '1.1'
__author__ = 'Alexander Solovyov'
__email__ = 'piranha@piranha.org.ua'
@@ -616,11 +616,14 @@
}
@command(name='_completion', hide=True)
-def completion(type=('t', 'bash', 'Completion type (bash or zsh)')):
+def completion(type=('t', 'bash', 'Completion type (bash or zsh)'),
+ # kwargs will catch every global option, which we get
+ # anyway, because middleware is skipped
+ **kwargs):
"""Outputs completion script for bash or zsh."""
prog_name = os.path.split(sys.argv[0])[1]
- print COMPLETIONS[type] % prog_name
+ print COMPLETIONS[type].strip() % prog_name
# --------
# Exceptions
--- a/tests/opster.t Mon Dec 06 23:45:14 2010 +0100
+++ b/tests/opster.t Tue Dec 07 12:26:36 2010 +0100
@@ -14,6 +14,8 @@
simple Just simple command to print keys of received arguments.
+
+
Ok, then let's run it::
$ run multicommands.py simple
@@ -39,6 +41,21 @@
-q --quiet suppress output
-h --help display help
+
+We also have completion::
+
+ $ run multicommands.py _completion
+ # opster bash completion start
+ _opster_completion()
+ {
+ COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
+ COMP_CWORD=$COMP_CWORD \
+ OPSTER_AUTO_COMPLETE=1 $1 ) )
+ }
+ complete -o default -F _opster_completion multicommands.py
+ # opster bash completion end
+
+
Now we're going to test if a script with a single command will work (not
everyone needs subcommands, you know)::
@@ -57,6 +74,7 @@
-t --test testing help for a function (default: test)
-h --help show help
+
Yeah, I've got it, I should supply some argument::
$ run test_opts.py right-here
@@ -67,6 +85,7 @@
'port': 8000,
'test': 'test'}
+
Should we check passing some invalid arguments? I think so::
$ run test_opts.py --wrong-option
@@ -85,4 +104,5 @@
-t --test testing help for a function (default: test)
-h --help show help
+
That's all for today; see you next time!