Don't show long options twice in print_help() from argparse

前端 未结 3 1331
一个人的身影
一个人的身影 2020-12-15 07:07

I have the following code:

parser = argparse.ArgumentParser(description=\'Postfix Queue Administration Tool\',
        prog=\'pqa\',
        usage=\'%(prog)s         


        
3条回答
  •  春和景丽
    2020-12-15 07:40

    Is the problem that is repeated in the help line?:

    -d , --domain 
    

    The argparse HelpFormatter does not give the user much control over this part of the display. As you have shown, you can set the usage line, the help text, and the metavar.

    You would have to subclass the HelpFormatter, and change one of the functions to produce something like:

    -d, --domain 
    

    It doesn't look like a complicated change, probably to the HelpFormatter._format_action_invocation method. But you need to be more explicit about what you want.

提交回复
热议问题