ANN: straight.command 0.1a1 - A command framework with a plugin architecture
Calvin Spealman
ironfroggy at gmail.com
Thu May 17 05:20:07 EDT 2012
I'd like to announce a new project, based on straight.plugin, a
command framework that provides a declarative way to define
command-line options, sub-commands, and allows plugins from
third-parties to expand commands.
This is all very early, I'm calling this version 0.1a1 and lots of
things are missing, but here is an example (which works) of a small
todo application built with this.
#!/usr/bin/env python
from __future__ import print_function
import sys
from straight.command import Command, Option, SubCommand
class List(Command):
def run_default(self, **extra):
for line in open(self.parent.args['filename']):
print(line.strip('\n'))
class Add(Command):
new_todo = Option(dest='new_todo', action='append')
def run_default(self, new_todo, **extra):
with open(self.parent.args['filename'], 'a') as f:
for one_todo in new_todo:
print(one_todo.strip('\n'), file=f)
class Todo(Command):
filename = Option(dest='filename', action='store')
list = SubCommand('list', List)
add = SubCommand('add', Add)
if __name__ == '__main__':
Todo().run(sys.argv[1:])
And a sample of the result of this little script:
$ ./todo.py todo.txt add "Write an example tool"
$ ./todo.py todo.txt add "Get the documentation cleaned up and on readthedocs"
$ ./todo.py todo.txt add "Blog about the project"
$ ./todo.py todo.txt list
Write an example tool
Get the documentation cleaned up and on readthedocs
Blog about the project
The documentation and source are both available now.
docs: http://straightcommand.readthedocs.org/
source: https://github.com/ironfroggy/straight.command
announcement: http://techblog.ironfroggy.com/2012/05/ann-straightcommand-01a1-command.html
--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
More information about the Python-list
mailing list