Commit 3231fbd3 authored by Fabien Potencier's avatar Fabien Potencier Committed by Benjamin Eberlei

Update Symfony\Component\Console to latest version

parent 5cd66217
......@@ -50,7 +50,7 @@ class RunSqlCommand extends Console\Command\Command
->setDescription('Executes arbitrary SQL directly from the command line.')
->setDefinition(array(
new InputArgument('sql', InputArgument::REQUIRED, 'The SQL statement to execute.'),
new InputOption('depth', null, InputOption::PARAMETER_REQUIRED, 'Dumping depth of result set.', 7)
new InputOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of result set.', 7)
))
->setHelp(<<<EOT
Executes arbitrary SQL directly from the command line.
......
......@@ -37,7 +37,7 @@ use Symfony\Component\Console\Helper\DialogHelper;
* Usage:
*
* $app = new Application('myapp', '1.0 (stable)');
* $app->addCommand(new SimpleCommand());
* $app->add(new SimpleCommand());
* $app->run();
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
......@@ -74,18 +74,18 @@ class Application
new DialogHelper(),
));
$this->addCommand(new HelpCommand());
$this->addCommand(new ListCommand());
$this->add(new HelpCommand());
$this->add(new ListCommand());
$this->definition = new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
new InputOption('--help', '-h', InputOption::PARAMETER_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::PARAMETER_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::PARAMETER_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::PARAMETER_NONE, 'Display this program version.'),
new InputOption('--ansi', '-a', InputOption::PARAMETER_NONE, 'Force ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::PARAMETER_NONE, 'Do not ask any interactive question.'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
new InputOption('--ansi', '-a', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
));
}
......@@ -181,7 +181,7 @@ class Application
}
// the command name MUST be the first element of the input
$command = $this->findCommand($name);
$command = $this->find($name);
$this->runningCommand = $command;
$statusCode = $command->run($input, $output);
......@@ -329,7 +329,7 @@ class Application
*/
public function register($name)
{
return $this->addCommand(new Command($name));
return $this->add(new Command($name));
}
/**
......@@ -340,7 +340,7 @@ class Application
public function addCommands(array $commands)
{
foreach ($commands as $command) {
$this->addCommand($command);
$this->add($command);
}
}
......@@ -353,7 +353,7 @@ class Application
*
* @return Command The registered command
*/
public function addCommand(Command $command)
public function add(Command $command)
{
$command->setApplication($this);
......@@ -375,7 +375,7 @@ class Application
*
* @throws \InvalidArgumentException When command name given does not exist
*/
public function getCommand($name)
public function get($name)
{
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
......@@ -386,7 +386,7 @@ class Application
if ($this->wantHelps) {
$this->wantHelps = false;
$helpCommand = $this->getCommand('help');
$helpCommand = $this->get('help');
$helpCommand->setCommand($command);
return $helpCommand;
......@@ -402,7 +402,7 @@ class Application
*
* @return Boolean true if the command exists, false otherwise
*/
public function hasCommand($name)
public function has($name)
{
return isset($this->commands[$name]) || isset($this->aliases[$name]);
}
......@@ -451,7 +451,7 @@ class Application
/**
* Finds a command by name or alias.
*
* Contrary to getCommand, this command tries to find the best
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @param string $name A command name or a command alias
......@@ -460,7 +460,7 @@ class Application
*
* @throws \InvalidArgumentException When command name is incorrect or ambiguous
*/
public function findCommand($name)
public function find($name)
{
// namespace
$namespace = '';
......@@ -481,7 +481,7 @@ class Application
$abbrevs = static::getAbbreviations($commands);
if (isset($abbrevs[$name]) && 1 == count($abbrevs[$name])) {
return $this->getCommand($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
return $this->get($namespace ? $namespace.':'.$abbrevs[$name][0] : $abbrevs[$name][0]);
}
if (isset($abbrevs[$name]) && count($abbrevs[$name]) > 1) {
......@@ -500,7 +500,7 @@ class Application
throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $fullName, $this->getAbbreviationSuggestions($abbrevs[$fullName])));
}
return $this->getCommand($abbrevs[$fullName][0]);
return $this->get($abbrevs[$fullName][0]);
}
/**
......@@ -512,7 +512,7 @@ class Application
*
* @return array An array of Command instances
*/
public function getCommands($namespace = null)
public function all($namespace = null)
{
if (null === $namespace) {
return $this->commands;
......@@ -566,7 +566,7 @@ class Application
*/
public function asText($namespace = null)
{
$commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
$messages = array($this->getHelp(), '');
if ($namespace) {
......@@ -607,7 +607,7 @@ class Application
*/
public function asXml($namespace = null, $asDom = false)
{
$commands = $namespace ? $this->getCommands($this->findNamespace($namespace)) : $this->commands;
$commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands;
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
......
......@@ -236,9 +236,9 @@ class Command
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param integer $mode The option mode: self::PARAMETER_REQUIRED, self::PARAMETER_NONE or self::PARAMETER_OPTIONAL
* @param integer $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or self::VALUE_NONE)
*
* @return Command The current instance
*/
......
......@@ -37,7 +37,7 @@ class HelpCommand extends Command
$this
->setDefinition(array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
))
->setName('help')
->setAliases(array('?'))
......@@ -65,7 +65,7 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->command) {
$this->command = $this->application->getCommand($input->getArgument('command_name'));
$this->command = $this->application->get($input->getArgument('command_name'));
}
if ($input->getOption('xml')) {
......
......@@ -33,7 +33,7 @@ class ListCommand extends Command
$this
->setDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
))
->setName('list')
->setDescription('Lists commands')
......
......@@ -88,7 +88,7 @@ class ArgvInput extends Input
$name = substr($token, 1);
if (strlen($name) > 1) {
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptParameter()) {
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
// an option with a value (with no space)
$this->addShortOption($name[0], substr($name, 1));
} else {
......@@ -115,7 +115,7 @@ class ArgvInput extends Input
}
$option = $this->definition->getOptionForShortcut($name[$i]);
if ($option->acceptParameter()) {
if ($option->acceptValue()) {
$this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
break;
......@@ -190,7 +190,7 @@ class ArgvInput extends Input
$option = $this->definition->getOption($name);
if (null === $value && $option->acceptParameter()) {
if (null === $value && $option->acceptValue()) {
// if option accepts an optional or mandatory argument
// let's see if there is one provided
$next = array_shift($this->parsed);
......@@ -202,11 +202,11 @@ class ArgvInput extends Input
}
if (null === $value) {
if ($option->isParameterRequired()) {
if ($option->isValueRequired()) {
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
}
$value = $option->isParameterOptional() ? $option->getDefault() : true;
$value = $option->isValueOptional() ? $option->getDefault() : true;
}
$this->options[$name] = $value;
......
......@@ -133,11 +133,11 @@ class ArrayInput extends Input
$option = $this->definition->getOption($name);
if (null === $value) {
if ($option->isParameterRequired()) {
if ($option->isValueRequired()) {
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
}
$value = $option->isParameterOptional() ? $option->getDefault() : true;
$value = $option->isValueOptional() ? $option->getDefault() : true;
}
$this->options[$name] = $value;
......
......@@ -18,7 +18,7 @@ namespace Symfony\Component\Console\Input;
*
* $definition = new InputDefinition(array(
* new InputArgument('name', InputArgument::REQUIRED),
* new InputOption('foo', 'f', InputOption::PARAMETER_REQUIRED),
* new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
* ));
*
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
......@@ -347,7 +347,7 @@ class InputDefinition
$elements = array();
foreach ($this->getOptions() as $option) {
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
$elements[] = sprintf('['.($option->isParameterRequired() ? '%s--%s="..."' : ($option->isParameterOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
$elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
}
foreach ($this->getArguments() as $argument) {
......@@ -399,7 +399,7 @@ class InputDefinition
$text[] = '<comment>Options:</comment>';
foreach ($this->getOptions() as $option) {
if ($option->acceptParameter() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', is_array($option->getDefault()) ? str_replace("\n", '', print_r($option->getDefault(), true)): $option->getDefault());
} else {
$default = '';
......@@ -450,13 +450,13 @@ class InputDefinition
$optionsXML->appendChild($optionXML = $dom->createElement('option'));
$optionXML->setAttribute('name', '--'.$option->getName());
$optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
$optionXML->setAttribute('accept_parameter', $option->acceptParameter() ? 1 : 0);
$optionXML->setAttribute('is_parameter_required', $option->isParameterRequired() ? 1 : 0);
$optionXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
$optionXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
$optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
$optionXML->appendChild($descriptionXML = $dom->createElement('description'));
$descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
if ($option->acceptParameter()) {
if ($option->acceptValue()) {
$optionXML->appendChild($defaultsXML = $dom->createElement('defaults'));
$defaults = is_array($option->getDefault()) ? $option->getDefault() : ($option->getDefault() ? array($option->getDefault()) : array());
foreach ($defaults as $default) {
......
......@@ -18,10 +18,10 @@ namespace Symfony\Component\Console\Input;
*/
class InputOption
{
const PARAMETER_NONE = 1;
const PARAMETER_REQUIRED = 2;
const PARAMETER_OPTIONAL = 4;
const PARAMETER_IS_ARRAY = 8;
const VALUE_NONE = 1;
const VALUE_REQUIRED = 2;
const VALUE_OPTIONAL = 4;
const VALUE_IS_ARRAY = 8;
protected $name;
protected $shortcut;
......@@ -34,9 +34,9 @@ class InputOption
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param integer $mode The option mode: self::PARAMETER_REQUIRED, self::PARAMETER_NONE or self::PARAMETER_OPTIONAL
* @param integer $mode The option mode: One of the VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
*
* @throws \InvalidArgumentException If option mode is invalid or incompatible
*/
......@@ -57,7 +57,7 @@ class InputOption
}
if (null === $mode) {
$mode = self::PARAMETER_NONE;
$mode = self::VALUE_NONE;
} else if (!is_int($mode) || $mode > 15) {
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
}
......@@ -67,8 +67,8 @@ class InputOption
$this->mode = $mode;
$this->description = $description;
if ($this->isArray() && !$this->acceptParameter()) {
throw new \InvalidArgumentException('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.');
if ($this->isArray() && !$this->acceptValue()) {
throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
}
$this->setDefault($default);
......@@ -95,43 +95,43 @@ class InputOption
}
/**
* Returns true if the option accept a parameter.
* Returns true if the option accepts a value.
*
* @return Boolean true if parameter mode is not self::PARAMETER_NONE, false otherwise
* @return Boolean true if value mode is not self::VALUE_NONE, false otherwise
*/
public function acceptParameter()
public function acceptValue()
{
return $this->isParameterRequired() || $this->isParameterOptional();
return $this->isValueRequired() || $this->isValueOptional();
}
/**
* Returns true if the option requires a parameter.
* Returns true if the option requires a value.
*
* @return Boolean true if parameter mode is self::PARAMETER_REQUIRED, false otherwise
* @return Boolean true if value mode is self::VALUE_REQUIRED, false otherwise
*/
public function isParameterRequired()
public function isValueRequired()
{
return self::PARAMETER_REQUIRED === (self::PARAMETER_REQUIRED & $this->mode);
return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
}
/**
* Returns true if the option takes an optional parameter.
* Returns true if the option takes an optional value.
*
* @return Boolean true if parameter mode is self::PARAMETER_OPTIONAL, false otherwise
* @return Boolean true if value mode is self::VALUE_OPTIONAL, false otherwise
*/
public function isParameterOptional()
public function isValueOptional()
{
return self::PARAMETER_OPTIONAL === (self::PARAMETER_OPTIONAL & $this->mode);
return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
}
/**
* Returns true if the option can take multiple values.
*
* @return Boolean true if mode is self::PARAMETER_IS_ARRAY, false otherwise
* @return Boolean true if mode is self::VALUE_IS_ARRAY, false otherwise
*/
public function isArray()
{
return self::PARAMETER_IS_ARRAY === (self::PARAMETER_IS_ARRAY & $this->mode);
return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
}
/**
......@@ -141,8 +141,8 @@ class InputOption
*/
public function setDefault($default = null)
{
if (self::PARAMETER_NONE === (self::PARAMETER_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::PARAMETER_NONE mode.');
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
}
if ($this->isArray()) {
......@@ -153,7 +153,7 @@ class InputOption
}
}
$this->default = $this->acceptParameter() ? $default : false;
$this->default = $this->acceptValue() ? $default : false;
}
/**
......
......@@ -97,7 +97,7 @@ class Shell
// task name?
if (false === strpos($text, ' ') || !$text) {
return array_keys($this->application->getCommands());
return array_keys($this->application->all());
}
// options and arguments?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment