@@ -912,14 +912,11 @@ def update_prog(self, prog: str) -> None:
912912 # Set the prog value for the parser's subcommands
913913 for action in self ._actions :
914914 if isinstance (action , argparse ._SubParsersAction ):
915- # Build the prefix that should be prepended to subcommand names
916- prefix = self .prog
915+ # Set the _SubParsersAction's _prog_prefix value. This ensures that any subcommands
916+ # added later via add_parser() will have the correct prog value.
917+ action ._prog_prefix = self .prog
917918 if positionals :
918- prefix += " " + " " .join (positionals )
919-
920- # Set the _SubParsersAction's _prog_prefix value. That way if its add_parser()
921- # method is called later, the correct prog value will be set on the parser being added.
922- action ._prog_prefix = prefix
919+ action ._prog_prefix += " " + " " .join (positionals )
923920
924921 # The keys of action.choices are subcommand names as well as subcommand aliases.
925922 # The aliases point to the same parser as the actual subcommand. We want to avoid
@@ -938,7 +935,7 @@ def update_prog(self, prog: str) -> None:
938935 if subcmd_parser in processed_parsers :
939936 continue
940937
941- subcmd_prog = f"{ prefix } { subcmd_name } "
938+ subcmd_prog = f"{ action . _prog_prefix } { subcmd_name } "
942939 subcmd_parser .update_prog (subcmd_prog ) # type: ignore[attr-defined]
943940 processed_parsers .append (subcmd_parser )
944941
0 commit comments