Cleo 0.3 is now out. It introduces decorators, validators, autocompletion and removes the need to
configure method when creating a command.
You can now declare a command, and its associated arguments and options, with decorators:
If you do not set the command name via the
command() decorator, it will automatically get the name of the decorated function.
Cleo now supports validators for arguments and options.
It is important to note that there is no
The reason is quite simple: By default, the command line arguments and options are considered strings, so there is no need to specify it.
Boolean() validator accepts the following values: 1, true, yes, y, on and their negatives (0, no, n, off) or native boolean types (True, False).
Integer and Float
These two are self explanatory.
Range() validator accepts a value that must be comprised inside a specified range.
The range can be of anything that can be compared to the specified value, like integers, floats or string.
The default validator for ranges is
Integer but it can be changed
Choice() (or its alias
Enum()) restricts a possible value to a specified set of choices.
Instead of declaring explicitely the validators it is possible to use their internal names:
When using named validators, the corresponding generated validator will have its default options.
Cleo now supports autocompletion of commands.
However it is not completely automatic. First you have to use the
Now, if your script is named
console autocompletion is set. If not add a line like the following:
A new way to declare commands via classes
In previous versions when you used classes to declare commands you needed to override
configure method, like so:
Now, it is no longer necessary since you can set the parameters as class variables:
There is a lot more you can do with Cleo, you can just give a look at the documentation: http://cleo.readthedocs.org.