test_opts.py
author Alexander Solovyov <piranha@piranha.org.ua>
Tue, 22 Sep 2009 14:24:57 +0300
changeset 93 625fd9886735
parent 92 979199a41678
child 94 0178aca18a6d
permissions -rwxr-xr-x
always call a function if it's default argument for an option

#!/usr/bin/env python

import sys

from opster 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='[-l HOST] DIR')
def main(*dirs, **opts):
    '''This is some command

    It looks very similar to some serve command
    '''
    print locals()

@command(usage='[-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 previous command
    '''
    print locals()

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