使用 argparse 从 --help 标志中获取帮助菜单的某个部分

在我的一个--help程序中传递时,我有一个非常长的帮助菜单:


optional arguments:

  -h, --help            show this help message and exit


mandatory arguments:

  arguments that have to be passed for the program to run


  -u URL, --url URL     Pass a single URL to detect the protection

...

request arguments:

  arguments that will control your requests


  --pa USER-AGENT       Provide your own personal agent to use it for the HTTP

...

encoding options:

  arguments that control the encoding of payloads


  -e PAYLOAD [TAMPER-SCRIPT-LOAD-PATH ...], --encode PAYLOAD [TAMPER-SCRIPT-LOAD-PATH ...]

...

output options:

  arguments that control how WhatWaf handles output


  -F, --format          Format the output into a dict and display it

...

misc arguments:

  arguments that don't fit in any other category


  --verbose             Run in verbose mode (more output)

...

构建参数的结构如下所示:


        mandatory = parser.add_argument_group("mandatory arguments",

                                              "arguments that have to be passed for the program to run")

        mandatory.add_argument("-u", "--url", dest="runSingleWebsite", metavar="URL",

                               help="Pass a single URL to detect the protection")

...

        req_args = parser.add_argument_group("request arguments",

                                             "arguments that will control your requests")

        req_args.add_argument("--pa", dest="usePersonalAgent", metavar="USER-AGENT",

                              help="Provide your own personal agent to use it for the HTTP requests")

...



翻阅古今
浏览 311回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python