argvee

Easily parse command line argument by virtue of the functions defined in the module
from argvee import Application
app = Application()

@app.cmd()
def add(a, b):
    ''' Add two numbers '''
    print('%s + %s = %s' % (a, b, int(a) + int(b)))

# $ python test.py add 1 2
# 1 + 2 = 3

@app.cmd()
def someflags(debug=False, verbose=True):
    ''' I have flags '''
    print('debug = %s' % debug)
    print('verbose = %s' % verbose)

# $ python test.py someflags
# debug = False
# verbose = True

@app.cmd()
def sayhello(name, debug=False):
    if debug:
        print('In debug mode')
    print('Hello, %s!' % name)
    if debug:
        print('done')

# $ python test.py sayhello joe --debug
# In debug mode
# Hello, joe!
# done

app.run()


# docstring goes in help for command
$ python test.py -h
usage: test.py [-h] {someflags,add,sayhello} ...

positional arguments:
  {someflags,add,sayhello}
    someflags           I have flags
    add                 Add two numbers
    sayhello

optional arguments:
  -h, --help            show this help message and exit

# debug and verbose are kwargs
# Any kwarg with default True/False becomes flags
$ python test.py someflags -h
usage: test.py someflags [-h] [--debug] [--verbose]

optional arguments:
  -h, --help  show this help message and exit
  --debug
  --verbose

$ python test.py someflags
debug = False
verbose = True

$ python test.py someflags --debug
debug = True
verbose = True

# Positional arg with kwargs
$ python test.py sayhello
usage: test.py sayhello [-h] [--debug] name
test.py sayhello: error: too few arguments
fusion@ultralisk:~$ python test.py sayhello joe
Hello, joe!
fusion@ultralisk:~$ python test.py sayhello joe --debug
In debug mode
Hello, joe!
done