test_opts.py
author Alexander Solovyov <piranha@piranha.org.ua>
Thu, 02 Jul 2009 22:17:21 +0300
changeset 29 d9a2fc1e5e90
parent 23 3cd126244055
child 30 1fc9a029d760
permissions -rwxr-xr-x
decorator to parse options for single command

#!/usr/bin/env python

import sys

from fancycmd import optionize

opts = [('l', 'listen', 'localhost', 'ip to listen on'),
        ('p', 'port', 8000, 'port to listen on'),
        ('d', 'daemonize', False, 'daemonize process'),
        ('', 'pid-file', '', 'name of file to write process ID to')]

@optionize(opts, usage='%prog [-l HOST] DIR')
def main(dirname, **opts):
    '''This is some command

    It looks very similar to some serve command
    '''
    print opts.get('pid_file')

if __name__ == '__main__':
    main()