Cleo 0.3 is now out. It introduces decorators, validators, autocompletion and removes the need to
declare a configure
method when creating a command.
Decorators
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.
Validators
Cleo now supports validators for arguments and options.
It is important to note that there is no String()
validator.
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
The 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
The 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/Enum
The Choice()
(or its alias Enum()
) restricts a possible value to a specified set of choices.
Named validators
Instead of declaring explicitely the validators it is possible to use their internal names:
Boolean
:boolean
Integer
:integer
Float
:float
Choice/Enum
:choice
orenum
Range
:range
When using named validators, the corresponding generated validator will have its default options.
Autocompletion
Cleo now supports autocompletion of commands.
However it is not completely automatic. First you have to use the bash_completion.sh
file:
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
the 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.