¿Es posible agregar un argumento a un python argparse.ArgumentParsersin que aparezca en el uso o en la ayuda ( script.py --help)?
¿Es posible agregar un argumento a un python argparse.ArgumentParsersin que aparezca en el uso o en la ayuda ( script.py --help)?
Respuestas:
Sí, puede configurar la helpopción add_argumenten argparse.SUPPRESS. Aquí hay un ejemplo de la documentación de argparse :
>>> parser = argparse.ArgumentParser(prog='frobble')
>>> parser.add_argument('--foo', help=argparse.SUPPRESS)
>>> parser.print_help()
usage: frobble [-h]
optional arguments:
-h, --help show this help message and exit
Lo hago agregando una opción para habilitar los ocultos, y lo agarro mirando sysv.args.
Si hace esto, debe incluir el argumento especial que elija sys.argvdirectamente en la lista de análisis si asume que la opción es -shabilitar opciones ocultas.
parser.add_argument('-a', '-axis',
dest="axis", action="store_true", default=False,
help="Rotate the earth")
if "-s" in sys.argv or "-secret" in sys.argv:
parser.add_argument('-s', '-secret',
dest="secret", action="store_true", default=False,
help="Enable secret options")
parser.add_argument('-d', '-drill',
dest="drill", action="store_true", default=False,
help="drill baby, drill")
sysv.argsun error tipográfico sys.argv?
test ==SUPPRESS==. Al menos cuando se usa conadd_parser.