Application base class.
description (str) – one-liner explaining the program purpose
version (str) – application version number
command_manager (cliff.commandmanager.CommandManager) – plugin loader
stdin (readable I/O stream) – Standard input stream
stdout (writable I/O stream) – Standard output stream
stderr (writable I/O stream) – Standard error output stream
interactive_app_factory (cliff.interactive.InteractiveApp) – callable to create an interactive application
deferred_help (bool) – True - Allow subcommands to accept –help with allowing to defer help print after initialize_app
Return an argparse option parser for this application.
Subclasses may override this method to extend the parser with more global options.
description (str) – full description of the application
version (str) – version number for the application
argparse_kwargs – extra keyword argument passed to the ArgumentParser constructor
Hook run after a command is done to shutdown the app.
cmd (cliff.command.Command) – command processor being invoked
result (int) – return value of cmd
err (Exception) – exception or None
Create logging handlers for any log output.
return fuzzy matches of unknown command
Hook for subclasses to take global initialization action after the arguments are parsed but before a command is run. Invoked only once, even in interactive mode.
argv – List of arguments, including the subcommand to run. Empty for interactive mode.
Perform any preliminary work needed to run a command.
cmd (cliff.command.Command) – command processor being invoked
Print help and exits if deferred help is enabled and requested.
without calling initialize_app if not self.deferred_help (default),
after initialize_app call if self.deferred_help,
during initialize_app call if self.deferred_help and subclass calls explicitly this method in initialize_app.
Equivalent to the main program for the application.
argv (list of str) – input arguments and options
Provides “interactive mode” features.
Refer to the cmd2 and cmd documentation for details about subclassing and configuring this class.
parent_app – The calling application (expected to be derived
from cliff.main.App
).
command_manager – A cliff.commandmanager.CommandManager
instance.
stdin – Standard input stream
stdout – Standard output stream
This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
_cmdloop() provides the main loop equivalent to cmd.cmdloop(). This is a wrapper around that which deals with the following extra features provided by cmd2: - transcript testing - intro banner - exit code
intro – if provided this overrides self.intro and serves as the intro banner printed once at start
Default tab-completion for command prefix with completer delimiter.
This method filters only cliff style commands matching provided command prefix (line) as cmd2 style commands cannot contain spaces. This method returns text + missing command part of matching commands. This method does not handle options in cmd2/cliff style commands, you must define complete_$method to handle them.
Tab-completion for command prefix without completer delimiter.
This method returns cmd style and cliff style commands matching provided command prefix (text).
Executed when the command given isn’t a recognized command implemented by a do_* method.
statement – Statement object with parsed input
Exit this application
List available commands or provide detailed help for a specific command
Return an alphabetized list of names comprising the attributes of the cmd2 class instance.
Hook method executed just before the command is executed by
onecmd()
and after adding it to history.
statement – subclass of str which also contains the parsed input
a potentially modified version of the input Statement object
Discovers commands and handles lookup based on argv data.
namespace – String containing the entrypoint namespace for the
plugins to be loaded. For example, 'cliff.formatter.list'
.
convert_underscores – Whether cliff should convert underscores to spaces in entry_point commands.
Adds another group of command entrypoints
Map an old command name to the new name.
old_name (str) – The old command name.
new_name (str) – The new command name.
Given an argument list, find a command and return the processor and any remaining arguments.
Returns a list of the loaded command groups
Returns a list of commands loaded for the specified group
Load all the commands from an entrypoint
Base class for command plugins.
When the command is instantiated, it loads extensions from a namespace based on the parent application namespace and the command name:
app.namespace + '.' + cmd_name.replace(' ', '_')
app (cliff.app.App) – Application instance invoking the command.
Return the command description.
The default is to use the first line of the class’ docstring
as the description. Set the _description
class attribute
to a one-line description of a command to use a different
value. This is useful for enabling translations, for example,
with _description
set to a string wrapped with a gettext
translation marker.
Return the command epilog.
Return an argparse.ArgumentParser
.
Invoked by the application when the command is run.
Developers implementing commands should override
take_action()
.
Developers creating new command base classes (such as
Lister
and ShowOne
) should override this
method to wrap take_action()
.
Return the value returned by take_action()
or 0.
Override to do something useful.
The returned value will be returned by the program.
Base class for command hooks.
app (cliff.command.Command) – Command instance being invoked
Called after the command’s take_action() method.
parsed_args (argparse.Namespace) – The arguments to the command.
return_code (int) – The value returned from take_action().
int
Called before the command’s take_action() method.
parsed_args (argparse.Namespace) – The arguments to the command.
argparse.Namespace
Return text to add to the command help epilog.
Return an argparse.ArgumentParser
.
parser (ArgumentParser) – An existing ArgumentParser instance to be modified.
ArgumentParser
Command base class for displaying data about a single object.
Implement the common task of converting a dict-based object to the two-column output that ShowOne expects.
String specifying the name of the default formatter.
String specifying the namespace to use for loading formatter plugins.
Use the formatter to generate the output.
parsed_args – argparse.Namespace instance with argument values
column_names – sequence of strings containing names of output columns
data – iterable with values matching the column names
Return a two-part tuple with a tuple of column names and a tuple of values.
Command base class for providing a list of data as output.
String specifying the name of the default formatter.
String specifying the namespace to use for loading formatter plugins.
Return an argparse.ArgumentParser
.
Whether sort procedure is performed by cliff itself.
Should be overridden (return False) when there is a need to implement custom sorting procedure or data is already sorted.
Use the formatter to generate the output.
parsed_args – argparse.Namespace instance with argument values
column_names – sequence of strings containing names of output columns
data – iterable with values matching the column names
Run command.
Return a tuple containing the column names and an iterable containing the data to be listed.
Base class for formatters that know how to deal with multiple objects.
Format and print the list from the iterable data source.
Data values can be primitive types like ints and strings, or
can be an instance of a FormattableColumn
for
situations where the value is complex, and may need to be
handled differently for human readable output vs. machine
readable output.
column_names – names of the columns
data – iterable data source, one tuple per object with values in order of column names
stdout – output stream where data should be written
parsed_args – argparse namespace from our local options
Base class for formatters that work with single objects.
Format and print the values associated with the single object.
Data values can be primitive types like ints and strings, or
can be an instance of a FormattableColumn
for
situations where the value is complex, and may need to be
handled differently for human readable output vs. machine
readable output.
column_names – names of the columns
data – iterable data source with values in order of column names
stdout – output stream where data should be written
parsed_args – argparse namespace from our local options
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.