simplify help sorter formatter
This commit is contained in:
parent
7cd05c6af6
commit
1daf98c919
@ -31,20 +31,24 @@ class BBSArgumentParser(argparse.ArgumentParser):
|
|||||||
|
|
||||||
class SortedHelpFormatter(argparse.HelpFormatter):
|
class SortedHelpFormatter(argparse.HelpFormatter):
|
||||||
def _iter_indented_subactions(self, action):
|
def _iter_indented_subactions(self, action):
|
||||||
try:
|
|
||||||
get_subactions = action._get_subactions
|
if not hasattr(action, '_get_subactions'):
|
||||||
except AttributeError:
|
return
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self._indent()
|
self._indent()
|
||||||
|
|
||||||
|
subactions = action._get_subactions
|
||||||
|
|
||||||
if isinstance(action, argparse._SubParsersAction):
|
if isinstance(action, argparse._SubParsersAction):
|
||||||
for subaction in sorted(
|
sorted_subactions = sorted(
|
||||||
get_subactions(),
|
subactions(),
|
||||||
key=lambda x: x.dest):
|
key=lambda x: x.dest)
|
||||||
yield subaction
|
|
||||||
else:
|
else:
|
||||||
for subaction in get_subactions():
|
sorted_subactions = subactions
|
||||||
|
|
||||||
|
for subaction in sorted_subactions:
|
||||||
yield subaction
|
yield subaction
|
||||||
|
|
||||||
self._dedent()
|
self._dedent()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user