summaryrefslogtreecommitdiff
path: root/cmd2/argparse_completer.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2018-06-13 10:59:21 -0400
committerEric Lin <anselor@gmail.com>2018-06-13 10:59:21 -0400
commitc897266b8e9a6bbce8aa577aa46e25ad1baa969d (patch)
tree64325315df72d811cb172c398645b586ea814245 /cmd2/argparse_completer.py
parent3ae71e80e61a908ad0a0dec84ee6496592176022 (diff)
downloadcmd2-git-c897266b8e9a6bbce8aa577aa46e25ad1baa969d.tar.gz
Added a check to verify the existence of a descriptive header. Added a constant. Updated example to use the constant.
Diffstat (limited to 'cmd2/argparse_completer.py')
-rwxr-xr-xcmd2/argparse_completer.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 1bc7f342..995aeb48 100755
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -77,6 +77,7 @@ from .rl_utils import rl_force_redisplay
# define the completion choices for the argument. You may provide a Collection or a Function.
ACTION_ARG_CHOICES = 'arg_choices'
ACTION_SUPPRESS_HINT = 'suppress_hint'
+ACTION_DESCRIPTIVE_COMPLETION_HEADER = 'desc_header'
class CompletionItem(str):
@@ -456,7 +457,11 @@ class AutoCompleter(object):
fill_width=fill_width)
completions_with_desc.append(entry)
- header = '\n{: <{token_width}}{}'.format(action.dest.upper(), action.desc_header, token_width=token_width+2)
+ try:
+ desc_header = action.desc_header
+ except AttributeError:
+ desc_header = 'Description'
+ header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width+2)
self._cmd2_app.completion_header = header
self._cmd2_app.display_matches = completions_with_desc