Overview

Namespaces

  • Webmozart
    • Console
      • Adapter
      • Api
        • Application
        • Args
          • Format
        • Command
        • Config
        • Event
        • Formatter
        • IO
        • Resolver
      • Args
      • Config
      • Formatter
      • Handler
        • Help
      • IO
        • InputStream
        • OutputStream
      • Process
      • Resolver
      • UI
        • Alignment
        • Component
        • Help
        • Layout
        • Style
      • Util

Classes

  • Command
  • CommandCollection

Exceptions

  • CannotAddCommandException
  • NoSuchCommandException
  • Overview
  • Namespace
  • Class

Class Command

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);
Namespace: Webmozart\Console\Api\Command
Author: Bernhard Schussek bschussek@gmail.com
Since: 1.0
Located at Api/Command/Command.php
Methods summary
public
# __construct( Webmozart\Console\Api\Config\CommandConfig $config, Webmozart\Console\Api\Application\Application $application = null, Webmozart\Console\Api\Command\Command $parentCommand = null )

Creates a new command.

Creates a new command.

Parameters

$config
The command configuration.
$application
The console application.
$parentCommand
The parent command.

Throws

LogicException
If the name of the command configuration is not set.
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

Webmozart\Console\Api\Config\CommandConfig
The command configuration.
public Webmozart\Console\Api\Args\Format\ArgsFormat
# getArgsFormat( )

Returns the arguments format of the command.

Returns the arguments format of the command.

Returns

Webmozart\Console\Api\Args\Format\ArgsFormat
The input definition.
public Webmozart\Console\Api\Application\Application
# getApplication( )

Returns the console application.

Returns the console application.

Returns

Webmozart\Console\Api\Application\Application
The console application.
public Webmozart\Console\Api\Command\Command
# getParentCommand( )

Returns the parent command.

Returns the parent command.

Returns

Webmozart\Console\Api\Command\Command
The parent command.
public Webmozart\Console\Api\Command\CommandCollection
# getSubCommands( )

Returns all sub-commands of the command.

Returns all sub-commands of the command.

Returns

Webmozart\Console\Api\Command\CommandCollection
The sub-commands.
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

Webmozart\Console\Api\Command\Command
The sub-command.

Throws

Webmozart\Console\Api\Command\NoSuchCommandException

If the sub-command with the given name does not exist.

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

Webmozart\Console\Api\Command\CommandCollection
The named commands.
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

Webmozart\Console\Api\Command\Command::getNamedSubCommands()
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

Webmozart\Console\Api\Command\CommandCollection
The default commands.
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

Webmozart\Console\Api\Command\Command::getDefaultSubCommands()
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

Webmozart\Console\Api\Args\Args
The parsed console arguments.

Throws

Webmozart\Console\Api\Args\CannotParseArgsException
If the arguments cannot be parsed.
public integer
# run( Webmozart\Console\Api\Args\RawArgs $args, Webmozart\Console\Api\IO\IO $io )

Executes the command for the given unparsed arguments.

Executes the command for the given unparsed arguments.

Parameters

$args
The unparsed console arguments.
$io
The I/O.

Returns

integer
Returns 0 on success and any other integer on error.
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
Webmozart Console API API documentation generated by ApiGen