An interface for shells that take a CommandCollection during initialization.
An interface for abstracting creation of command and shell instances.
Marker interface for commands that should be hidden from the help output and shell completion while remaining fully executable.
use Cake\Command\Command;
use Cake\Console\CommandHiddenInterface;
class InternalMaintenanceCommand extends Command implements CommandHiddenInterface
{
// Command implementation
}
Describe the interface between a command and the surrounding console libraries.
A wrapper around the various IO operations shell tasks need to do.
Packages up the stdout, stderr, and stdin streams providing a simple consistent interface for shells to use. This class also makes mocking streams easy to do in unit tests.
Provides an interface for interacting with a command's options and arguments.
Base class for console commands.
Provides hooks for common command features:
initialize Acts as a post-construct hook.buildOptionParser Build/Configure the option parser for your command.execute Execute your command with parsed Arguments and ConsoleIoCakePHP fires a number of life cycle callbacks during each command execution. By implementing a method you can receive the related events. The available callbacks are:
beforeExecute(EventInterface $event)
Called immediately prior to the command's run method. This is a good place to do
general logic that applies to command setup.afterExecute(EventInterface $event)
Called immediately after the command's run method, unless an exception occurs.Collection for Commands.
Used by Applications to specify their console commands. CakePHP will use the mapped commands to construct and dispatch shell commands.
This is a factory for creating Command instances.
This factory can be replaced or extended if you need to customize building your command objects.
Run CLI commands for the provided application.
Scans the filesystem for command classes.
Implementation detail behind CommandCollection's discovery methods.
Not part of the supported public API - use CommandCollection
(e.g. discoverDirectory()) instead.
Object wrapper for interacting with stdin
An object to represent a single argument used in the command line. ConsoleOptionParser creates these when you use addArgument()
An object to represent a single option used in the command line. ConsoleOptionParser creates these when you use addOption()
A wrapper around the various IO operations shell tasks need to do.
Packages up the stdout, stderr, and stdin streams providing a simple consistent interface for shells to use. This class also makes mocking streams easy to do in unit tests.
Handles parsing the ARGV in the command line and provides support for GetOpt compatible option definition. Provides a builder pattern implementation for creating shell option parsers.
Named arguments come in two forms, long and short. Long arguments are preceded
by two - and give a more verbose option name. i.e. --version. Short arguments are
preceded by one - and are only one character long. They usually match with a long option,
and provide a more terse alternative.
Options can be defined with both long and short forms. By using $parser->addOption()
you can define new options. The name of the option is used as its long form, and you
can supply an additional short form, with the short option. Short options should
only be one letter long. Using more than one letter for a short option will raise an exception.
Calling options can be done using syntax similar to most *nix command line tools. Long options
can either include an = or leave it out.
cake my_command --connection default --name=something
Short options can be defined singly or in groups.
cake my_command -cn
Short options can be combined into groups as seen above. Each letter in a group will be treated as a separate option. The previous example is equivalent to:
cake my_command -c -n
Short options can also accept values:
cake my_command -c default
If no positional arguments are defined, all of them will be parsed. If you define positional arguments any arguments greater than those defined will cause exceptions. Additionally you can declare arguments as optional, by setting the required param to false.
$parser->addArgument('model', ['required' => false]);
By providing help text for your positional arguments and named arguments, the ConsoleOptionParser
can generate a help display for you. You can view the help for shells by using the --help or -h switch.
Object wrapper for outputting information from a shell application. Can be connected to any stream resource that can be used with fopen()
Can generate colorized output on consoles that support it. There are a few built in styles
error Error messages.warning Warning messages.info Informational messages.comment Additional text.question Magenta text used for user promptssuccess Green foreground textinfo.bg Cyan background with black textwarning.bg Yellow background with black texterror.bg Red background with black textsuccess.bg Green background with black textBy defining styles with addStyle() you can create custom console styles.
You can format console output using tags with the name of the style to apply. From inside a shell object
$this->out('<warning>Overwrite:</warning> foo.php was overwritten.');
This would create orange 'Overwrite:' text, while the rest of the text would remain the normal color. See ConsoleOutput::styles() to learn more about defining your own styles. Nested styles are not supported at this time.
HelpFormatter formats help for console shells. Can format to either text or XML formats. Uses ConsoleOptionParser methods to generate help.
Generally not directly used. Using $parser->help($command, 'xml'); is usually
how you would access help. Or via the --help=xml option on the command line.
Xml output is useful for integration with other tools like IDE's or other build tools.
Base class for Helpers.
Console Helpers allow you to package up reusable blocks of Console output logic. For example creating tables, progress bars or ascii art.
Registry for Helpers. Provides features for lazily loading helpers.