aboutsummaryrefslogtreecommitdiffstats
path: root/becommands/help.py
diff options
context:
space:
mode:
Diffstat (limited to 'becommands/help.py')
-rw-r--r--becommands/help.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/becommands/help.py b/becommands/help.py
index bf0b4fc..7e0209d 100644
--- a/becommands/help.py
+++ b/becommands/help.py
@@ -21,20 +21,28 @@ __desc__ = __doc__
def execute(args):
"""
Print help of specified command.
+ >>> execute(["help"])
+ Usage: be help [COMMAND]
+ <BLANKLINE>
+ Options:
+ -h, --help Print a help message
+ --complete Print a list of available completions
+ <BLANKLINE>
+ Print help for specified command or list of all commands.
+ <BLANKLINE>
"""
- options, args = get_parser().parse_args(args)
+ parser = get_parser()
+ options, args = parser.parse_args(args)
+ complete(options, args, parser)
if len(args) > 1:
- raise cmdutil.UserError("Too many arguments.")
+ raise cmdutil.UsageError("Too many arguments.")
if len(args) == 0:
print cmdutil.help()
else:
try:
print cmdutil.help(args[0])
except AttributeError:
- print "No help available"
-
- return
-
+ print "No help available"
def get_parser():
parser = cmdutil.CmdOptionParser("be help [COMMAND]")
@@ -46,3 +54,12 @@ Print help for specified command or list of all commands.
def help():
return get_parser().help_str() + longhelp
+
+def complete(options, args, parser):
+ for option, value in cmdutil.option_value_pairs(options, parser):
+ if value == "--complete":
+ # no argument-options at the moment, so this is future-proofing
+ raise cmdutil.GetCompletions()
+ if "--complete" in args:
+ cmds = [command for command,module in cmdutil.iter_commands()]
+ raise cmdutil.GetCompletions(cmds)