tests/test_opts.py
author Dmitriy Morozov <dmitriy@mrzv.org>
Sat, 29 May 2010 15:46:31 -0700
changeset 105 1ce5c137b3e5
parent 101 7507884b8dff
child 111 e40251bf5a23
permissions -rw-r--r--
Added the ability to provide a completer for arguments to options

#!/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'),
            test=('t', lambda x: x or 'test', 'testing help for a function')):
    '''Command with option declaration as keyword arguments

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

if __name__ == '__main__':
    #main(argv=sys.argv[1:])
    another(argv=sys.argv[1:])