test.py
author Alexander Solovyov <piranha@piranha.org.ua>
Fri, 24 Jul 2009 13:16:11 +0300
changeset 50 ae36fb1b69a2
parent 32 9d42e3d16bcf
child 60 1d27eceed4d2
permissions -rwxr-xr-x
ability to use commands as usual functions

#!/usr/bin/env python

import sys

from finaloption import dispatch, command


@command(usage='[-t]', shortlist=True)
def simple(test=('t', False, 'just test execution')):
    '''Just simple command to do nothing.

    I assure you! Nothing to look here. ;-)
    '''
    print locals()

cplx_opts = [('p', 'pass', False, 'don\'t run the command'),
             ('', 'exit', 0, 'exit with supplied code (default: 0)')]

@command(cplx_opts, usage='[-p] [--exit value] ...', name='complex')
def complex_(*args, **opts):
    '''That's more complex command indented to do something

    Let's try to do that (what?!)
    '''
    if opts.get('pass'):
        return
    # test ui
    if opts.get('exit'):
        sys.exit(opts['exit'])

if __name__ == '__main__':
    dispatch()