python optparse, how to include additional info in usage output?
        Posted  
        
            by CarpeNoctem
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by CarpeNoctem
        
        
        
        Published on 2009-12-07T01:48:08Z
        Indexed on 
            2010/05/13
            20:54 UTC
        
        
        Read the original article
        Hit count: 399
        
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: check_dell.py [options]
options:
-h, --help     show this help message and exit
-s, --storage  checks virtual and physical disks
-c, --chassis  checks specified chassis components
I would like it to include usage examples for the less *nix literate users at my work. Something like this:
usage: check_dell.py [options]
options:
-h, --help     show this help message and exit
-s, --storage  checks virtual and physical disks
-c, --chassis  checks specified chassis components
Examples:
check_dell -c all
check_dell -c fans memory voltage
check_dell -s
How would I accomplish this? What optparse options allow for such? Current code:
import optparse
def main():
    parser = optparse.OptionParser()
    parser.add_option('-s', '--storage', action='store_true', default=False, help='checks virtual and physical disks')
    parser.add_option('-c', '--chassis', action='store_true', default=False, help='checks specified chassis components')
(opts, args) = parser.parse_args()
© Stack Overflow or respective owner