A console command.
A Command
object contains all the information that is necessary to describe
and run a console command. Use the Webmozart\Console\Api\Config\CommandConfig
class to configure
a command:
$config = CommandConfig::create() ->setDescription('List and manage servers')
->beginSubCommand('add') ->setDescription('Add a new server') ->addArgument('host', InputArgument::REQUIRED) ->addOption('port', 'p', InputOption::VALUE_OPTIONAL, null, 80) ->end()
;
$command = new Command($config);
Methods summary
public
|
|
public
string
|
#
getName( )
Returns the name of the command.
Returns the name of the command.
Returns
string The name of the command.
|
public
string|null
|
#
getShortName( )
Returns the short name of the command.
Returns the short name of the command.
This method only returns a value if an Webmozart\Console\Api\Config\OptionCommandConfig was
passed to the constructor. Otherwise this method returns null .
Returns
string|null The short name or null if the command is not an
option command.
|
public
string[]
|
#
getAliases( )
Returns the alias names of the command.
Returns the alias names of the command.
Returns
string[] An array of alias names of the command.
|
public
boolean
|
#
hasAliases( )
Returns whether the command has aliases.
Returns whether the command has aliases.
Returns
boolean Returns true if the command has aliases and false
otherwise.
|
public
Webmozart\Console\Api\Config\CommandConfig
|
#
getConfig( )
Returns the configuration of the command.
Returns the configuration of the command.
Returns
|
public
Webmozart\Console\Api\Args\Format\ArgsFormat
|
#
getArgsFormat( )
Returns the arguments format of the command.
Returns the arguments format of the command.
Returns
|
public
Webmozart\Console\Api\Application\Application
|
#
getApplication( )
Returns the console application.
Returns the console application.
Returns
|
public
Webmozart\Console\Api\Command\Command
|
#
getParentCommand( )
Returns the parent command.
Returns the parent command.
Returns
|
public
Webmozart\Console\Api\Command\CommandCollection
|
#
getSubCommands( )
Returns all sub-commands of the command.
Returns all sub-commands of the command.
Returns
|
public
Webmozart\Console\Api\Command\Command
|
#
getSubCommand( string $name )
Returns the sub-command with a specific name.
Returns the sub-command with a specific name.
Parameters
- $name
- The name of the sub-command.
Returns
Throws
|
public
boolean
|
#
hasSubCommand( string $name )
Returns whether a sub-command with the given name exists.
Returns whether a sub-command with the given name exists.
Parameters
- $name
- The name of the sub-command.
Returns
boolean Returns true if a sub-command with that name exists and
false otherwise.
|
public
boolean
|
#
hasSubCommands( )
Returns whether the command has any sub-commands.
Returns whether the command has any sub-commands.
Returns
boolean Returns true if the command has sub-commands and false
otherwise.
|
public
Webmozart\Console\Api\Command\CommandCollection
|
#
getNamedSubCommands( )
Returns all sub-commands that are not anonymous.
Returns all sub-commands that are not anonymous.
Returns
|
public
boolean
|
#
hasNamedSubCommands( )
Returns whether the command has any commands that are not anonymous.
Returns whether the command has any commands that are not anonymous.
Returns
boolean Returns true if the command has named commands and
false otherwise.
See
|
public
Webmozart\Console\Api\Command\CommandCollection
|
#
getDefaultSubCommands( )
Returns the commands that should be executed if no explicit command is
passed.
Returns the commands that should be executed if no explicit command is
passed.
Returns
|
public
boolean
|
#
hasDefaultSubCommands( )
Returns whether the command has any default commands.
Returns whether the command has any default commands.
Returns
boolean Returns true if the command has default commands and
false otherwise.
See
|
public
Webmozart\Console\Api\Args\Args
|
#
parseArgs( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null )
Parses the raw console arguments and returns the parsed arguments.
Parses the raw console arguments and returns the parsed arguments.
Parameters
- $args
- The raw console arguments.
- $lenient
Whether the parser should ignore parse errors.
If true , the parser will not throw any
exceptions when parse errors occur.
Returns
Throws
|
public
integer
|
|
public
integer
|
#
handle( Webmozart\Console\Api\Args\Args $args, Webmozart\Console\Api\IO\IO $io )
Executes the command for the given parsed arguments.
Executes the command for the given parsed arguments.
Parameters
- $args
- The parsed console arguments.
- $io
- The I/O.
Returns
integer Returns 0 on success and any other integer on error.
Throws
Exception
|