Permalink
Browse files

Added README

  • Loading branch information...
1 parent e3770a9 commit 047b189371416e255b6ab7663889382d9be628e6 @ironfroggy committed May 20, 2012
Showing with 54 additions and 0 deletions.
  1. +54 −0 README
View
54 README
@@ -0,0 +1,54 @@
+``straight.command``
+====================
+
+``straight.command`` is a framework for easily describing commands and their
+options, and allowing them to be extended with additional options and even
+sub-commands through easy-to-maintain plugins, via the ``straight.plugin`` plugin
+loader. Command-line options can be defined in a declarative syntax, which
+should be very familiar to many developers.
+
+This is a very early stage in development.
+
+
+Example
+-------
+
+.. code-block:: python
+
+ #!/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:])
+
+
+This example shows several commands with declaratively defined options,
+including two of them being declared as subcommands of the third.
+
+We can see a number of the features of ``straight.command`` in this example.
+
+Command options are declared with instances of ``Option`` assigned in the
+``Command`` subclass, much like the declarative nature of many ORM tools
+declaring table columns, so this should be familiar to many developers.

0 comments on commit 047b189

Please sign in to comment.