From 98dc4737992a08aa9722f4b531ab417f4c83fd88 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Apr 2026 04:47:56 +0000 Subject: [PATCH] docs: fix parameter names showing as None in CLI usage docs Required arguments with no explicit metavar were displaying as in the generated command reference docs. Fix by falling back to the argparse convention: positional args use dest, optional args use dest.upper(). Fixes #2578 Fixes #2642 Agent-Logs-Url: https://github.com/canonical/charmcraft/sessions/214f19c4-3b9e-4123-9e2d-d2fc75b2ca6d Co-authored-by: lengau <4305943+lengau@users.noreply.github.com> --- tools/docs/gen_cli_docs.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/docs/gen_cli_docs.py b/tools/docs/gen_cli_docs.py index e2297a705..98a2f95ce 100755 --- a/tools/docs/gen_cli_docs.py +++ b/tools/docs/gen_cli_docs.py @@ -107,7 +107,16 @@ def main(docs_dir): for action in sorted(p._actions, key=lambda a: a.dest): if action.required: - required.append((action.dest, ([action.metavar], action.help))) + # Fall back to dest-derived name if metavar is not explicitly set, + # matching argparse's own behaviour: positional args use dest, + # optional args use dest.upper(). + if action.metavar is not None: + metavar = action.metavar + elif action.option_strings: + metavar = action.dest.upper() + else: + metavar = action.dest + required.append((action.dest, ([metavar], action.help))) elif action.option_strings and action.dest not in global_options: options[action.dest] = (action.option_strings, action.help)