PHP Class Webmozart\Console\Api\Command\Command

A Command object contains all the information that is necessary to describe and run a console command. Use the {@link CommandConfig} class to configure a command: php $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);
Since: 1.0
Author: Bernhard Schussek ([email protected])
Mostrar archivo Open project: webmozart/console Class Usage Examples

Public Methods

Method Description
__construct ( CommandConfig $config, Webmozart\Console\Api\Application\Application $application = null, Command $parentCommand = null ) Creates a new command.
getAliases ( ) : string[] Returns the alias names of the command.
getApplication ( ) : Webmozart\Console\Api\Application\Application Returns the console application.
getArgsFormat ( ) : ArgsFormat Returns the arguments format of the command.
getConfig ( ) : CommandConfig Returns the configuration of the command.
getDefaultSubCommands ( ) : CommandCollection Returns the commands that should be executed if no explicit command is passed.
getName ( ) : string Returns the name of the command.
getNamedSubCommands ( ) : CommandCollection Returns all sub-commands that are not anonymous.
getParentCommand ( ) : Command Returns the parent command.
getShortName ( ) : string | null Returns the short name of the command.
getSubCommand ( string $name ) : Command Returns the sub-command with a specific name.
getSubCommands ( ) : CommandCollection Returns all sub-commands of the command.
handle ( Args $args, IO $io ) : integer Executes the command for the given parsed arguments.
hasAliases ( ) : boolean Returns whether the command has aliases.
hasDefaultSubCommands ( ) : boolean Returns whether the command has any default commands.
hasNamedSubCommands ( ) : boolean Returns whether the command has any commands that are not anonymous.
hasSubCommand ( string $name ) : boolean Returns whether a sub-command with the given name exists.
hasSubCommands ( ) : boolean Returns whether the command has any sub-commands.
parseArgs ( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null ) : Args Parses the raw console arguments and returns the parsed arguments.
run ( Webmozart\Console\Api\Args\RawArgs $args, IO $io ) : integer Executes the command for the given unparsed arguments.

Private Methods

Method Description
addSubCommand ( SubCommandConfig $config ) Adds a sub-command.
doHandle ( Args $args, IO $io )
getBaseFormat ( ) : ArgsFormat Returns the inherited arguments format of the command.
validateSubCommandName ( SubCommandConfig $config )
warnIfProcessTitleNotSupported ( $processTitle, IO $io )

Method Details

__construct() public method

Creates a new command.
public __construct ( CommandConfig $config, Webmozart\Console\Api\Application\Application $application = null, Command $parentCommand = null )
$config Webmozart\Console\Api\Config\CommandConfig The command configuration.
$application Webmozart\Console\Api\Application\Application The console application.
$parentCommand Command The parent command.

getAliases() public method

Returns the alias names of the command.
public getAliases ( ) : string[]
return string[] An array of alias names of the command.

getApplication() public method

Returns the console application.
public getApplication ( ) : Webmozart\Console\Api\Application\Application
return Webmozart\Console\Api\Application\Application The console application.

getArgsFormat() public method

Returns the arguments format of the command.
public getArgsFormat ( ) : ArgsFormat
return Webmozart\Console\Api\Args\Format\ArgsFormat The input definition.

getConfig() public method

Returns the configuration of the command.
public getConfig ( ) : CommandConfig
return Webmozart\Console\Api\Config\CommandConfig The command configuration.

getDefaultSubCommands() public method

Returns the commands that should be executed if no explicit command is passed.
public getDefaultSubCommands ( ) : CommandCollection
return CommandCollection The default commands.

getName() public method

Returns the name of the command.
public getName ( ) : string
return string The name of the command.

getNamedSubCommands() public method

Returns all sub-commands that are not anonymous.
public getNamedSubCommands ( ) : CommandCollection
return CommandCollection The named commands.

getParentCommand() public method

Returns the parent command.
public getParentCommand ( ) : Command
return Command The parent command.

getShortName() public method

This method only returns a value if an {@link OptionCommandConfig} was passed to the constructor. Otherwise this method returns null.
public getShortName ( ) : string | null
return string | null The short name or `null` if the command is not an option command.

getSubCommand() public method

Returns the sub-command with a specific name.
public getSubCommand ( string $name ) : Command
$name string The name of the sub-command.
return Command The sub-command.

getSubCommands() public method

Returns all sub-commands of the command.
public getSubCommands ( ) : CommandCollection
return CommandCollection The sub-commands.

handle() public method

Executes the command for the given parsed arguments.
public handle ( Args $args, IO $io ) : integer
$args Webmozart\Console\Api\Args\Args The parsed console arguments.
$io Webmozart\Console\Api\IO\IO The I/O.
return integer Returns 0 on success and any other integer on error.

hasAliases() public method

Returns whether the command has aliases.
public hasAliases ( ) : boolean
return boolean Returns `true` if the command has aliases and `false` otherwise.

hasDefaultSubCommands() public method

Returns whether the command has any default commands.
See also: getDefaultSubCommands()
public hasDefaultSubCommands ( ) : boolean
return boolean Returns `true` if the command has default commands and `false` otherwise.

hasNamedSubCommands() public method

Returns whether the command has any commands that are not anonymous.
See also: getNamedSubCommands()
public hasNamedSubCommands ( ) : boolean
return boolean Returns `true` if the command has named commands and `false` otherwise.

hasSubCommand() public method

Returns whether a sub-command with the given name exists.
public hasSubCommand ( string $name ) : boolean
$name string The name of the sub-command.
return boolean Returns `true` if a sub-command with that name exists and `false` otherwise.

hasSubCommands() public method

Returns whether the command has any sub-commands.
public hasSubCommands ( ) : boolean
return boolean Returns `true` if the command has sub-commands and `false` otherwise.

parseArgs() public method

Parses the raw console arguments and returns the parsed arguments.
public parseArgs ( Webmozart\Console\Api\Args\RawArgs $args, boolean $lenient = null ) : Args
$args Webmozart\Console\Api\Args\RawArgs The raw console arguments.
$lenient boolean Whether the parser should ignore parse errors. If `true`, the parser will not throw any exceptions when parse errors occur.
return Webmozart\Console\Api\Args\Args The parsed console arguments.

run() public method

Executes the command for the given unparsed arguments.
public run ( Webmozart\Console\Api\Args\RawArgs $args, IO $io ) : integer
$args Webmozart\Console\Api\Args\RawArgs The unparsed console arguments.
$io Webmozart\Console\Api\IO\IO The I/O.
return integer Returns 0 on success and any other integer on error.