test_opts.py
author Alexander Solovyov <piranha@piranha.org.ua>
Mon, 13 Jul 2009 18:54:38 +0300
changeset 36 0cb832d5f1a9
parent 31 80701f91156c
child 43 fd3c1f0abab4
permissions -rwxr-xr-x
setup.py

#!/usr/bin/env python

import sys

from finaloption import command

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')]

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

    It looks very similar to some serve command
    '''
    print opts

@command(usage='%prog [-l HOST] DIR')
def another(dirname,
            listen=('l', 'localhost', 'ip to listen on'),
            port=('p', 8000, 'port to listen on'),
            daemonize=('d', False, 'daemonize process'),
            pid_file=('', '', 'name of file to write process ID to')):
    '''Command with option declaration as keyword arguments

    Otherwise it's the same as previons command
    '''
    print locals()

if __name__ == '__main__':
    #main()
    another()