Tofu Roll
While working on the second version of Done, a basic command line todo list tool, I realized I had written a bunch of code to generalize routing command line arguments to python methods. It seemed pretty useful, so I extracted it and turned it into a miniature framework for writing command line applications.
Code speaks louder than words, so..:
greetings.py:
from tofuroll.tofuroll import *
class app(TofuApp):
@command
def hi(self, options, args):
if options.name:
print "Hi, %s" % options.name
else:
print "Hi there"
@option
def name(self):
return {
'help' : "someone's name"
}
if __name__ == '__main__':
app().run()
on the command line:
$: python greetings.py hi Hi there $: python greetings.py hi -n nate Hi, nate
For a more interesting example involving the peewee orm, check out done2.py.
tofuroll can be installed via pip (pip install tofuroll) and its source is available on github.