aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbe5
-rw-r--r--becommands/list.py4
-rw-r--r--completion/be.bash12
-rw-r--r--libbe/cmdutil.py20
4 files changed, 16 insertions, 25 deletions
diff --git a/be b/be
index ab6ddeb..35dab69 100755
--- a/be
+++ b/be
@@ -24,11 +24,10 @@ __doc__ == cmdutil.help()
if len(sys.argv) == 1 or sys.argv[1] in ('--help', '-h'):
print cmdutil.help()
-elif sys.argv[1] == '--commands':
+elif sys.argv[1] == '--complete':
for command, module in cmdutil.iter_commands():
print command
-elif sys.argv[1] == '--options':
- print '\n'.join(cmdutil.options())
+ print '\n'.join(["--help","--complete","--options"])
else:
try:
try:
diff --git a/becommands/list.py b/becommands/list.py
index 7c51f11..25e72d3 100644
--- a/becommands/list.py
+++ b/becommands/list.py
@@ -37,11 +37,11 @@ def execute(args, test=False):
for option in [o.dest for o in parser.option_list if o.dest != None]:
value = getattr(options, option)
- if value == "--options":
+ if value == "--complete":
if option == "status":
raise cmdutil.GetCompletions(status_values)
raise cmdutil.GetCompletions()
- if "--options" in args:
+ if "--complete" in args:
raise cmdutil.GetCompletions() # no completions for arguments yet
if len(args) > 0:
diff --git a/completion/be.bash b/completion/be.bash
index 8789352..dbe1214 100644
--- a/completion/be.bash
+++ b/completion/be.bash
@@ -11,13 +11,9 @@
# "An introduction to bash completion: part 2"
# http://www.debian-administration.org/articles/317
-# Support commands of the form:
-# be <command> [<long option>] [<long option>] ...
# Requires:
-# be --commands
-# to print a list of available commands
-# be command [<option> ...] --options
-# to print a list of available long options
+# be [X Y Z] --complete
+# to print a list of available completions at that point
_be()
{
local cur prev opts
@@ -27,7 +23,7 @@ _be()
if [ $COMP_CWORD -eq 1 ]; then
# no command yet, show all commands
- COMPREPLY=( $( compgen -W "$(be --commands)" -- $cur ) )
+ COMPREPLY=( $( compgen -W "$(be --complete)" -- $cur ) )
else
# remove the first word (should be "be") for security reasons
unset COMP_WORDS[0]
@@ -36,7 +32,7 @@ _be()
for i in `seq $COMP_CWORD ${#COMP_WORDS[@]}`; do
unset COMP_WORDS[$i];
done
- COMPREPLY=( $( compgen -W "$(be "${COMP_WORDS[@]}" --options)" -- $cur ) )
+ COMPREPLY=( $( compgen -W "$(be "${COMP_WORDS[@]}" --complete)" -- $cur ) )
fi
}
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index aad6bbe..2bfe6d4 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -86,16 +86,12 @@ def help(cmd=None):
ret.append("be %s%*s %s" % (name, numExtraSpaces, "", desc))
return "\n".join(ret)
-def options(cmd=None):
- if cmd != None:
- parser = get_command(cmd).get_parser()
- longopts = []
- for opt in parser.option_list:
- longopts.append(opt.get_opt_string())
- return longopts
- else:
- # These probably shouldn't be hardcoded...
- return ["--help","--commands","--options"]
+def options(cmd):
+ parser = get_command(cmd).get_parser()
+ longopts = []
+ for opt in parser.option_list:
+ longopts.append(opt.get_opt_string())
+ return longopts
def raise_get_help(option, opt, value, parser):
raise GetHelp
@@ -109,9 +105,9 @@ class CmdOptionParser(optparse.OptionParser):
self.remove_option("-h")
self.add_option("-h", "--help", action="callback",
callback=raise_get_help, help="Print a help message")
- self.add_option("--options", action="callback",
+ self.add_option("--complete", action="callback",
callback=raise_get_completions,
- help="Print a list of available long options")
+ help="Print a list of available completions")
def error(self, message):
raise UsageError(message)