Use metavar to list the choices for a CLI arg when custom values are also accepted (#21760)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-07-28 20:31:10 +01:00
committed by GitHub
parent 7d44c691b0
commit 94b71ae106
3 changed files with 20 additions and 7 deletions

View File

@@ -62,6 +62,11 @@ class MarkdownFormatter(HelpFormatter):
choices = f'`{"`, `".join(str(c) for c in choices)}`'
self._markdown_output.append(
f"Possible choices: {choices}\n\n")
elif ((metavar := action.metavar)
and isinstance(metavar, (list, tuple))):
metavar = f'`{"`, `".join(str(m) for m in metavar)}`'
self._markdown_output.append(
f"Possible choices: {metavar}\n\n")
self._markdown_output.append(f"{action.help}\n\n")