@@ -64,7 +64,8 @@ def _load_subcommand_descriptions() -> Iterator[tuple[str, str]]:
6464 try :
6565 description = module .parser_description
6666 except AttributeError :
67- continue
67+ # log an error here, but don't fail the full enumeration
68+ pass
6869 else :
6970 yield command , description .split ('\n \n ' , 1 )[0 ]
7071
@@ -88,10 +89,10 @@ def format_help(self):
8889 bold (underline (__ ('Commands:' ))),
8990 '\n ' ,
9091 ]
91- help_fragments . extend (
92+ help_fragments += [
9293 f' { command_name : <{command_max_length }} { command_desc } '
9394 for command_name , command_desc in commands
94- )
95+ ]
9596 help_fragments .append ('\n ' )
9697
9798 # self._action_groups[1] is self._optionals
@@ -100,7 +101,10 @@ def format_help(self):
100101 for argument_group in self ._action_groups [1 :]:
101102 if arguments := [action for action in argument_group ._group_actions
102103 if action .help != argparse .SUPPRESS ]:
103- help_fragments .extend (self ._format_optional_arguments (arguments , argument_group .title ))
104+ help_fragments += self ._format_optional_arguments (
105+ arguments ,
106+ argument_group .title or '' ,
107+ )
104108
105109 help_fragments += [
106110 '\n ' ,
@@ -109,13 +113,18 @@ def format_help(self):
109113 ]
110114 return '' .join (help_fragments )
111115
112- def _format_optional_arguments (self , options : list [argparse .Action ], title : str ) -> Iterator [str ]:
116+ def _format_optional_arguments (
117+ self ,
118+ actions : Iterable [argparse .Action ],
119+ title : str ,
120+ ) -> Iterator [str ]:
113121 yield '\n '
114122 yield bold (underline (title + ':' ))
115123 yield '\n '
116124
117- for action in options :
118- opt = self ._format_option_string (action .option_strings )
125+ for action in actions :
126+ prefix = ' ' * all (o [1 ] == '-' for o in action .option_strings )
127+ opt = prefix + ' ' + ', ' .join (map (bold , action .option_strings ))
119128 if action .nargs != 0 :
120129 opt += ' ' + self ._format_metavar (
121130 action .nargs , action .metavar , action .choices , action .dest ,
@@ -125,13 +134,6 @@ def _format_optional_arguments(self, options: list[argparse.Action], title: str)
125134 if action_help := (action .help or '' ).strip ():
126135 yield from (f' { line } \n ' for line in action_help .splitlines ())
127136
128- @staticmethod
129- def _format_option_string (option_strings : Sequence [str ]) -> str :
130- # hide 'colour'
131- option_strings = [o for o in option_strings if o != '--colour' ]
132- prefix = ' ' * all (o [1 ] == '-' for o in option_strings )
133- return prefix + ' ' + ', ' .join (map (bold , option_strings ))
134-
135137 @staticmethod
136138 def _format_metavar (
137139 nargs : int | str | None ,
0 commit comments