diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-02-13 15:02:42 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-02-13 15:02:42 -0500 |
commit | cdd81905b5c8c9321d48786c0912368157587477 (patch) | |
tree | 52472ba098f393f439b80438a8aa5eba9a0169aa /cmd2 | |
parent | 09985f668ecdbad87f9fc725e82b3c99cbd2ef5d (diff) | |
download | cmd2-git-cdd81905b5c8c9321d48786c0912368157587477.tar.gz |
Using metavar in CompletionItem header if it has been set
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/argparse_completer.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 6513fe13..185e01a2 100644 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -444,7 +444,9 @@ class AutoCompleter: completions.sort(key=self._cmd2_app.default_sort_key) self._cmd2_app.matches_sorted = True - token_width = ansi.style_aware_wcswidth(action.dest) + # If a metavar was defined, use that instead of the dest field + destination = action.metavar if action.metavar else action.dest + token_width = ansi.style_aware_wcswidth(destination) completions_with_desc = [] for item in completions: @@ -463,7 +465,7 @@ class AutoCompleter: desc_header = getattr(action, ATTR_DESCRIPTIVE_COMPLETION_HEADER, None) if desc_header is None: desc_header = DEFAULT_DESCRIPTIVE_HEADER - header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width + 2) + header = '\n{: <{token_width}}{}'.format(destination.upper(), desc_header, token_width=token_width + 2) self._cmd2_app.completion_header = header self._cmd2_app.display_matches = completions_with_desc |