python optparse, how to include additional info in usage output?

前端 未结 6 2095
野性不改
野性不改 2021-02-01 04:03

Using python\'s optparse module I would like to add extra example lines below the regular usage output. My current help_print() output looks like this:

usage: ch         


        
6条回答
  •  伪装坚强ぢ
    2021-02-01 04:46

    Use the usage parameter:

    usage = "usage: %prog [options] arg1 arg2"
    parser = OptionParser(usage=usage)
    

    You can add more through (just an example):

    group = OptionGroup(parser, "Dangerous Options",
                        "Caution: use these options at your own risk.  "
                        "It is believed that some of them bite.")
    group.add_option("-g", action="store_true", help="Group option.")
    parser.add_option_group(group)
    

    Example output:

    usage: [options] arg1 arg2

    options: -h, --help show this help message and exit
    -v, --verbose make lots of noise [default]
    -q, --quiet be vewwy quiet (I'm hunting wabbits)
    -fFILE, --file=FILE write output to FILE
    -mMODE, --mode=MODE interaction mode: one of 'novice', 'intermediate', [default], 'expert'

    Dangerous Options: Caution: use of these options is at your own risk. It is believed that some of them bite. -g Group option.

    Have a look here.

提交回复
热议问题