你如何在argparse中打印所有级别的帮助?

时间:2013-07-12 11:00:15

标签: python argparse

如果我有这样的代码:

import argparse

# create the top-level parser
parser = argparse.ArgumentParser(prog='PROG')
parser.add_argument('--foo', action='store_true', help='foo help')
subparsers = parser.add_subparsers(help='sub-command help')

# create the parser for the "a" command
parser_a = subparsers.add_parser('a', help='a help')
parser_a.add_argument('bar', type=int, help='bar help')

# create the parser for the "b" command
parser_b = subparsers.add_parser('b', help='b help')
parser_b.add_argument('--baz', choices='XYZ', help='baz help')


parser.parse_args()

在subparser中寻求帮助会导致:

$ ./test.py a -h
usage: PROG a [-h] bar

positional arguments:
  bar         bar help

optional arguments:
  -h, --help  show this help message and exit

当在subparser中寻求帮助时,如何让它显示--foo选项及其帮助?

0 个答案:

没有答案
相关问题