diff options
author | Eric Lin <anselor@gmail.com> | 2018-06-13 10:59:21 -0400 |
---|---|---|
committer | Eric Lin <anselor@gmail.com> | 2018-06-13 10:59:21 -0400 |
commit | c897266b8e9a6bbce8aa577aa46e25ad1baa969d (patch) | |
tree | 64325315df72d811cb172c398645b586ea814245 /cmd2/argparse_completer.py | |
parent | 3ae71e80e61a908ad0a0dec84ee6496592176022 (diff) | |
download | cmd2-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-x | cmd2/argparse_completer.py | 7 |
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 |