lepture/terminal — pull request #5 by kadefor (2013-05-25 07:52:21+00:00)
Title: add "run" to Command

(dev2)# cat aa.py
from terminal import Command, red

def show(cmd):
"""
foo's subcommand run

:parms cmd: foo command
"""

if cmd.color:
print(red('show'))
else:
print('show')

cmd_show = Command('show', 'show something', version='1.0.0', run=show)
cmd_show.option('-c, --color', 'disable or enable colors')

cmd_show2 = Command('show2', 'show2 something', version='1.0.1')
cmd_show2.option('-c, --color', 'disable or enable colors')
cmd_show2.run = show
(dev2)#
(dev2)# cat bb.py
from terminal import Command
from aa import cmd_show, cmd_show2

program = Command('foo', version='1.0.0')
program.action(cmd_show)
program.action(cmd_show2)

program.parse()
(dev2)#
(dev2)# python bb.py -h

foo 1.0.0

Usage: foo [option]

Options:

-h, --help output the help menu
-V, --version output the version number

Commands:

show show something
show2 show2 something

(dev2)# python bb.py show
show
(dev2)# python bb.py show -c
show
(dev2)# python bb.py show2
show
(dev2)# python bb.py show2 -c
show
(dev2)#