summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-09-23 20:57:47 +0000
committerEric Lin <anselor@gmail.com>2018-09-23 20:57:47 +0000
commit7cc94ab98c007210b344fbb1af965570fae63959 (patch)
tree80fe9c72f4a2512337710a68bc0ef67054d23375 /cmd2/cmd2.py
parentdbe485957b421f6fd973b3a493de7b264b363d54 (diff)
downloadcmd2-git-7cc94ab98c007210b344fbb1af965570fae63959.tar.gz
Added the the ability to format help to the AutoCompleter to support sub-command specific help lookup.
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py13
1 files changed, 4 insertions, 9 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 546b03cd..26cfbf4a 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1609,7 +1609,7 @@ class Cmd(cmd.Cmd):
try:
cmd_func = getattr(self, 'do_' + tokens[cmd_index])
parser = getattr(cmd_func, 'argparser')
- completer = AutoCompleter(parser)
+ completer = AutoCompleter(parser, cmd2_app=self)
matches = completer.complete_command_help(tokens[1:], text, line, begidx, endidx)
except AttributeError:
pass
@@ -2347,14 +2347,9 @@ Usage: Usage: unalias [-a] name [name ...]
# Check to see if this function was decorated with an argparse ArgumentParser
func = getattr(self, funcname)
if hasattr(func, 'argparser'):
- # Function has an argparser, so get help based on all the arguments in case there are sub-commands
- new_arglist = arglist[1:]
- new_arglist.append('-h')
-
- # Temporarily redirect all argparse output to both sys.stdout and sys.stderr to self.stdout
- with redirect_stdout(self.stdout):
- with redirect_stderr(self.stdout):
- func(new_arglist)
+ completer = AutoCompleter(getattr(func, 'argparser'), cmd2_app=self)
+
+ self.poutput(completer.format_help(arglist))
else:
# No special behavior needed, delegate to cmd base class do_help()
cmd.Cmd.do_help(self, funcname[3:])