def _format_action(self, action):
if type(action) == argparse._SubParsersAction:
# calculate the subcommand max length
subactions = action._get_subactions()
invocations = [self._format_action_invocation(a)
for a in subactions]
self._subcommand_max_length = max(len(i) for i in invocations)
if type(action) == argparse._SubParsersAction._ChoicesPseudoAction:
# format subcommand help line
subcommand = self._format_action_invocation(action)
help_text = self._expand_help(action)
return (" {:{width}}\t\t{} \n").format(
subcommand, help_text, width=self._subcommand_max_length)
elif type(action) == argparse._SubParsersAction:
# eliminate subcommand choices line {cmd1, cmd2}
msg = ''
for subaction in action._get_subactions():
msg += self._format_action(subaction)
return msg
else:
return super(SimpleHelpFormatter, self)._format_action(action)
评论列表
文章目录