Skip to content

Commit cdd8190

Browse files
committed
Using metavar in CompletionItem header if it has been set
1 parent 09985f6 commit cdd8190

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cmd2/argparse_completer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ def _format_completions(self, action, completions: List[Union[str, CompletionIte
444444
completions.sort(key=self._cmd2_app.default_sort_key)
445445
self._cmd2_app.matches_sorted = True
446446

447-
token_width = ansi.style_aware_wcswidth(action.dest)
447+
# If a metavar was defined, use that instead of the dest field
448+
destination = action.metavar if action.metavar else action.dest
449+
token_width = ansi.style_aware_wcswidth(destination)
448450
completions_with_desc = []
449451

450452
for item in completions:
@@ -463,7 +465,7 @@ def _format_completions(self, action, completions: List[Union[str, CompletionIte
463465
desc_header = getattr(action, ATTR_DESCRIPTIVE_COMPLETION_HEADER, None)
464466
if desc_header is None:
465467
desc_header = DEFAULT_DESCRIPTIVE_HEADER
466-
header = '\n{: <{token_width}}{}'.format(action.dest.upper(), desc_header, token_width=token_width + 2)
468+
header = '\n{: <{token_width}}{}'.format(destination.upper(), desc_header, token_width=token_width + 2)
467469

468470
self._cmd2_app.completion_header = header
469471
self._cmd2_app.display_matches = completions_with_desc

0 commit comments

Comments
 (0)