CLY 0.9 released

CLY is a project I've been working on for a while now, and I've finally gotten around to releasing it.

It's basically a CLI parser and grammar constructor that lets you easily add command-line interfaces to your applications:

echo.py:

from cly import *

def echo(text):
    print text

grammar = Grammar(
    echo=Node(help='Echo text')(
        text=Variable(help='Text to echo', pattern=r'.+')(
            Action(callback=echo),
            ),
        ),
    )

interact(grammar)

CLY automatically generates contextual help and provides tab completion (fully customisable). If you ran the above program it would work like this:

cly> ?
  echo Echo text
cly> echo
         ^ more input required (expected <text>)
cly> echo ?
  <text> Text to echo
cly> echo some text
some text

Grammars can also be defined in XML. Here's the above example rewritten to use an XML grammar:

echo.xml:

<?xml version="1.0"?>
<grammar xmlns="http://swapoff.org/cly/xml">
  <node name="echo" help="Echo text">
    <variable name="text" pattern=".+" help="Text to echo">
      <action callback="echo"/>
    </variable>
  </node>
</grammar>

echo.py:

from cly import *

def echo(text):
    print text

grammar = Grammar.from_xml(open('echo.xml').read(), echo=echo)

interact(grammar)

More examples are available in the tutorial, developers guide and the API documentation.