Cleo 0.4 is now out. Commands have been largely improved and are now easier to use. Helpers have also been improved. Overall, Cleo is now more intuitive.
This version breaks the backward compatibility for the following parts:
- The
DialogHelper
has been replaced by a more robustQuestionHelper
- The
ProgressHelper
has been removed and theProgressBar
class must be used - When using decorators or dictionaries, the signature of the callback has changed and accepts only a
Command
instance
New Commands
The Command
class has been improved, with a new way of describing it via docstring and several helper methods:
Command signature
The definition of a command can now be declared in the docstring:
The handle()
method
The logic of the command now needs to be put in the handle()
method:
Helper methods
Commands are now easier to use with new helper methods.
argument()
and option()
These methods make it easier to access command's arguments and options.
line()
This methods writes a new line to the output:
A style can also be passed as a second argument:
The native styles have their own helper methods:
call()
Calls another command:
If you want to suppress the output of the executed command,
you can use the call_silent()
method instead.
confirm()
Confirm a question with the user.
In this case, the user will be asked “Continue with this action?”. If the user answers with y it returns True or False if they answer with n. The second argument to confirm() is the default value to return if the user doesn’t enter any valid input. If the second argument is not provided, True is assumed.
ask()
Prompt the user for input.
secret()
Prompt the user for input but hide the answer from the console.
choice()
Give the user a single choice from an list of answers.
render_table()
Format input to textual table.
You can also use the table()
method to retrieve a Table
instance.
progress_bar()
Creates a new progress bar.
set_style()
Sets a new formatting style.
Progress Bar
The ProgressHelper
has been removed and the improved ProgressBar
(or its helper method progress_bar()
)
must now be used instead:
Table
The TableHelper
has been deprecated and the improved Table
(or its helper method table()
)
should now be used instead:
Question Helper
The DialogHelper
has been removed and the improved QuestionHelper
(or one of its helper methods)
must now be used instead:
More verbosity
Two other levels of verbosity (-vv
and -vvv
) have been added.
Command description format
Commands description can now be output as json and markdown:
Decorators and dictionaries notation
When using decorators or dictionaries, the signature of the callback has changed and accepts only a Command
instance:
This is so that helper methods can be accessed inside code functions.
Autocompletion
Autocompletion has also been improved, and the old bash_completion.sh
has been removed.
To activate support for autocompletion, pass a complete
keyword when initializing
your application:
Now, register completion for your application by running one of the following in a terminal,
replacing [program]
with the command you use to run your application:
By default this registers completion for the absolute path to you application,
which will work if the program is accessible on your PATH.
You can specify a program name to complete for instead using the -p\--program
option,
which is required if you're using an alias to run the program.
If you want the completion to apply automatically for all new shell sessions,
add the command to your shell's profile (eg. ~/.bash_profile
or ~/.zshrc
)
Fixes
- Values are now properly cast by validators
- Fixing "flag" not being set properly
- Progress bar now behaves properly (Fixes #37)
- The
-n|--no-interaction
option behaves properly (Fixes #38 and #39)
There is a lot more you can do with Cleo, you can just give a look at the documentation: http://cleo.readthedocs.org.