diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2016-12-30 23:23:10 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-12-30 23:23:10 +0100 |
commit | 893389f3782379f25bc8220845fe83a78e3125c7 (patch) | |
tree | fb99e86c7c462ba9bda28f9af9e11e32d5f11ff6 /mp_tool/util.py | |
parent | 17a3e144dd0b0675bb994d082d1f50abde9e03da (diff) | |
download | mp-tool-893389f3782379f25bc8220845fe83a78e3125c7.tar.gz mp-tool-893389f3782379f25bc8220845fe83a78e3125c7.zip |
restructure commandline arguments
Diffstat (limited to 'mp_tool/util.py')
-rw-r--r-- | mp_tool/util.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/mp_tool/util.py b/mp_tool/util.py index b289124..73b8a42 100644 --- a/mp_tool/util.py +++ b/mp_tool/util.py @@ -2,6 +2,19 @@ import argparse import platform +class UsageAction(argparse._HelpAction): + def __call__(self, parser, namespace, values, option_string=None): + formatter = parser._get_formatter() + formatter.add_usage(parser.usage, + parser._actions, + parser._mutually_exclusive_groups) + + formatter.start_section(parser._optionals.title) + formatter.end_section() + print(formatter.format_help()) + parser.exit(0) + + class HelpAction(argparse._HelpAction): def __call__(self, parser, namespace, values, option_string=None): formatter = parser._get_formatter() @@ -24,13 +37,7 @@ class HelpAction(argparse._HelpAction): for subaction in subparsers_action._get_subactions(): subparser = subparsers[subaction.dest] usage = formatter._format_actions_usage(subparser._actions, []) - usage_parent = formatter._format_actions_usage(filter( - lambda a: not (isinstance(a, HelpAction) or isinstance(a, argparse._SubParsersAction)), - parser._actions), []) - formatter.start_section("{} {} {} {}".format(formatter._prog, - usage_parent, - subaction.dest, - usage)) + formatter.start_section("{} {}".format(subaction.dest, usage)) formatter.add_text(subaction.help) formatter.add_arguments(subparser._positionals._group_actions) formatter.add_arguments(filter(lambda a: not isinstance(a, argparse._HelpAction), |