print help for humans
(parser)
| 51 | |
| 52 | |
| 53 | def print_help(parser): |
| 54 | """print help for humans""" |
| 55 | print(parser.description) |
| 56 | print('\ncommands:\n') |
| 57 | |
| 58 | # https://stackoverflow.com/questions/20094215/argparse-subparser-monolithic-help-output |
| 59 | # retrieve subparsers from parser |
| 60 | subparsers_actions = [ |
| 61 | action for action in parser._actions |
| 62 | if isinstance(action, argparse._SubParsersAction)] |
| 63 | # there will probably only be one subparser_action, |
| 64 | # but better safe than sorry |
| 65 | for subparsers_action in subparsers_actions: |
| 66 | # get all subparsers and print help |
| 67 | for choice in subparsers_action._choices_actions: |
| 68 | print(' {:<19} {}'.format(choice.dest, choice.help)) |
| 69 | |
| 70 | def main(): |
| 71 | parser = argparse.ArgumentParser( |