1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Update Symfony\Component\Console to latest version

This commit is contained in:
Fabien Potencier 2010-11-28 16:59:23 +08:00 committed by Benjamin Eberlei
parent 796b62cd2c
commit 892eec2f26
20 changed files with 99 additions and 99 deletions

View File

@ -49,19 +49,19 @@ class ResultCommand extends Console\Command\Command
->setDescription('Clear result cache of the various cache drivers.') ->setDescription('Clear result cache of the various cache drivers.')
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'id', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'id', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'ID(s) of the cache entry to delete (accepts * wildcards).', array() 'ID(s) of the cache entry to delete (accepts * wildcards).', array()
), ),
new InputOption( new InputOption(
'regex', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'regex', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Delete cache entries that match the given regular expression(s).', array() 'Delete cache entries that match the given regular expression(s).', array()
), ),
new InputOption( new InputOption(
'prefix', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'prefix', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Delete cache entries that have the given prefix(es).', array() 'Delete cache entries that have the given prefix(es).', array()
), ),
new InputOption( new InputOption(
'suffix', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'suffix', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Delete cache entries that have the given suffix(es).', array() 'Delete cache entries that have the given suffix(es).', array()
), ),
)) ))

View File

@ -112,16 +112,16 @@ class ConvertDoctrine1SchemaCommand extends Console\Command\Command
'The path to generate your Doctrine 2.X mapping information.' 'The path to generate your Doctrine 2.X mapping information.'
), ),
new InputOption( new InputOption(
'from', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Optional paths of Doctrine 1.X schema information.', 'Optional paths of Doctrine 1.X schema information.',
array() array()
), ),
new InputOption( new InputOption(
'extend', null, InputOption::PARAMETER_OPTIONAL, 'extend', null, InputOption::VALUE_OPTIONAL,
'Defines a base class to be extended by generated entity classes.' 'Defines a base class to be extended by generated entity classes.'
), ),
new InputOption( new InputOption(
'num-spaces', null, InputOption::PARAMETER_OPTIONAL, 'num-spaces', null, InputOption::VALUE_OPTIONAL,
'Defines the number of indentation spaces', 4 'Defines the number of indentation spaces', 4
) )
)) ))

View File

@ -53,7 +53,7 @@ class ConvertMappingCommand extends Console\Command\Command
->setDescription('Convert mapping information between supported formats.') ->setDescription('Convert mapping information between supported formats.')
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'A string pattern used to match entities that should be processed.' 'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(
@ -67,11 +67,11 @@ class ConvertMappingCommand extends Console\Command\Command
'from-database', null, null, 'Whether or not to convert mapping information from existing database.' 'from-database', null, null, 'Whether or not to convert mapping information from existing database.'
), ),
new InputOption( new InputOption(
'extend', null, InputOption::PARAMETER_OPTIONAL, 'extend', null, InputOption::VALUE_OPTIONAL,
'Defines a base class to be extended by generated entity classes.' 'Defines a base class to be extended by generated entity classes.'
), ),
new InputOption( new InputOption(
'num-spaces', null, InputOption::PARAMETER_OPTIONAL, 'num-spaces', null, InputOption::VALUE_OPTIONAL,
'Defines the number of indentation spaces', 4 'Defines the number of indentation spaces', 4
) )
)) ))

View File

@ -49,7 +49,7 @@ class EnsureProductionSettingsCommand extends Console\Command\Command
->setDescription('Verify that Doctrine is properly configured for a production environment.') ->setDescription('Verify that Doctrine is properly configured for a production environment.')
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'complete', null, InputOption::PARAMETER_NONE, 'complete', null, InputOption::VALUE_NONE,
'Flag to also inspect database connection existance.' 'Flag to also inspect database connection existance.'
) )
)) ))

View File

@ -52,34 +52,34 @@ class GenerateEntitiesCommand extends Console\Command\Command
->setDescription('Generate entity classes and method stubs from your mapping information.') ->setDescription('Generate entity classes and method stubs from your mapping information.')
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'A string pattern used to match entities that should be processed.' 'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(
'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.' 'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.'
), ),
new InputOption( new InputOption(
'generate-annotations', null, InputOption::PARAMETER_OPTIONAL, 'generate-annotations', null, InputOption::VALUE_OPTIONAL,
'Flag to define if generator should generate annotation metadata on entities.', false 'Flag to define if generator should generate annotation metadata on entities.', false
), ),
new InputOption( new InputOption(
'generate-methods', null, InputOption::PARAMETER_OPTIONAL, 'generate-methods', null, InputOption::VALUE_OPTIONAL,
'Flag to define if generator should generate stub methods on entities.', true 'Flag to define if generator should generate stub methods on entities.', true
), ),
new InputOption( new InputOption(
'regenerate-entities', null, InputOption::PARAMETER_OPTIONAL, 'regenerate-entities', null, InputOption::VALUE_OPTIONAL,
'Flag to define if generator should regenerate entity if it exists.', false 'Flag to define if generator should regenerate entity if it exists.', false
), ),
new InputOption( new InputOption(
'update-entities', null, InputOption::PARAMETER_OPTIONAL, 'update-entities', null, InputOption::VALUE_OPTIONAL,
'Flag to define if generator should only update entity if it exists.', true 'Flag to define if generator should only update entity if it exists.', true
), ),
new InputOption( new InputOption(
'extend', null, InputOption::PARAMETER_OPTIONAL, 'extend', null, InputOption::VALUE_OPTIONAL,
'Defines a base class to be extended by generated entity classes.' 'Defines a base class to be extended by generated entity classes.'
), ),
new InputOption( new InputOption(
'num-spaces', null, InputOption::PARAMETER_OPTIONAL, 'num-spaces', null, InputOption::VALUE_OPTIONAL,
'Defines the number of indentation spaces', 4 'Defines the number of indentation spaces', 4
) )
)) ))

View File

@ -50,7 +50,7 @@ class GenerateProxiesCommand extends Console\Command\Command
->setDescription('Generates proxy classes for entity classes.') ->setDescription('Generates proxy classes for entity classes.')
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'A string pattern used to match entities that should be processed.' 'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(

View File

@ -51,7 +51,7 @@ class GenerateRepositoriesCommand extends Console\Command\Command
->setDescription('Generate repository classes from your mapping information.') ->setDescription('Generate repository classes from your mapping information.')
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'filter', null, InputOption::PARAMETER_REQUIRED | InputOption::PARAMETER_IS_ARRAY, 'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'A string pattern used to match entities that should be processed.' 'A string pattern used to match entities that should be processed.'
), ),
new InputArgument( new InputArgument(

View File

@ -50,20 +50,20 @@ class RunDqlCommand extends Console\Command\Command
->setDefinition(array( ->setDefinition(array(
new InputArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.'), new InputArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.'),
new InputOption( new InputOption(
'hydrate', null, InputOption::PARAMETER_REQUIRED, 'hydrate', null, InputOption::VALUE_REQUIRED,
'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.', 'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.',
'object' 'object'
), ),
new InputOption( new InputOption(
'first-result', null, InputOption::PARAMETER_REQUIRED, 'first-result', null, InputOption::VALUE_REQUIRED,
'The first result in the result set.' 'The first result in the result set.'
), ),
new InputOption( new InputOption(
'max-result', null, InputOption::PARAMETER_REQUIRED, 'max-result', null, InputOption::VALUE_REQUIRED,
'The maximum number of results in the result set.' 'The maximum number of results in the result set.'
), ),
new InputOption( new InputOption(
'depth', null, InputOption::PARAMETER_REQUIRED, 'depth', null, InputOption::VALUE_REQUIRED,
'Dumping depth of Entity graph.', 7 'Dumping depth of Entity graph.', 7
) )
)) ))

View File

@ -53,7 +53,7 @@ class CreateCommand extends AbstractCommand
) )
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'dump-sql', null, InputOption::PARAMETER_NONE, 'dump-sql', null, InputOption::VALUE_NONE,
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.' 'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
) )
)) ))

View File

@ -53,15 +53,15 @@ class DropCommand extends AbstractCommand
) )
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'dump-sql', null, InputOption::PARAMETER_NONE, 'dump-sql', null, InputOption::VALUE_NONE,
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.' 'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
), ),
new InputOption( new InputOption(
'force', null, InputOption::PARAMETER_NONE, 'force', null, InputOption::VALUE_NONE,
"Don't ask for the deletion of the database, but force the operation to run." "Don't ask for the deletion of the database, but force the operation to run."
), ),
new InputOption( new InputOption(
'full-database', null, InputOption::PARAMETER_NONE, 'full-database', null, InputOption::VALUE_NONE,
'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.' 'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.'
), ),
)) ))

View File

@ -53,15 +53,15 @@ class UpdateCommand extends AbstractCommand
) )
->setDefinition(array( ->setDefinition(array(
new InputOption( new InputOption(
'complete', null, InputOption::PARAMETER_NONE, 'complete', null, InputOption::VALUE_NONE,
'If defined, all assets of the database which are not relevant to the current metadata will be dropped.' 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.'
), ),
new InputOption( new InputOption(
'dump-sql', null, InputOption::PARAMETER_NONE, 'dump-sql', null, InputOption::VALUE_NONE,
'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.' 'Instead of try to apply generated SQLs into EntityManager Storage Connection, output them.'
), ),
new InputOption( new InputOption(
'force', null, InputOption::PARAMETER_NONE, 'force', null, InputOption::VALUE_NONE,
"Don't ask for the incremental update of the database, but force the operation to run." "Don't ask for the incremental update of the database, but force the operation to run."
), ),
)) ))

View File

@ -37,7 +37,7 @@ use Symfony\Component\Console\Helper\DialogHelper;
* Usage: * Usage:
* *
* $app = new Application('myapp', '1.0 (stable)'); * $app = new Application('myapp', '1.0 (stable)');
* $app->addCommand(new SimpleCommand()); * $app->add(new SimpleCommand());
* $app->run(); * $app->run();
* *
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
@ -74,18 +74,18 @@ class Application
new DialogHelper(), new DialogHelper(),
)); ));
$this->addCommand(new HelpCommand()); $this->add(new HelpCommand());
$this->addCommand(new ListCommand()); $this->add(new ListCommand());
$this->definition = new InputDefinition(array( $this->definition = new InputDefinition(array(
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
new InputOption('--help', '-h', InputOption::PARAMETER_NONE, 'Display this help message.'), new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--quiet', '-q', InputOption::PARAMETER_NONE, 'Do not output any message.'), new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
new InputOption('--verbose', '-v', InputOption::PARAMETER_NONE, 'Increase verbosity of messages.'), new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
new InputOption('--version', '-V', InputOption::PARAMETER_NONE, 'Display this program version.'), new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
new InputOption('--ansi', '-a', InputOption::PARAMETER_NONE, 'Force ANSI output.'), new InputOption('--ansi', '-a', InputOption::VALUE_NONE, 'Force ANSI output.'),
new InputOption('--no-interaction', '-n', InputOption::PARAMETER_NONE, 'Do not ask any interactive question.'), 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 // the command name MUST be the first element of the input
$command = $this->findCommand($name); $command = $this->find($name);
$this->runningCommand = $command; $this->runningCommand = $command;
$statusCode = $command->run($input, $output); $statusCode = $command->run($input, $output);
@ -329,7 +329,7 @@ class Application
*/ */
public function register($name) 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) public function addCommands(array $commands)
{ {
foreach ($commands as $command) { foreach ($commands as $command) {
$this->addCommand($command); $this->add($command);
} }
} }
@ -353,7 +353,7 @@ class Application
* *
* @return Command The registered command * @return Command The registered command
*/ */
public function addCommand(Command $command) public function add(Command $command)
{ {
$command->setApplication($this); $command->setApplication($this);
@ -375,7 +375,7 @@ class Application
* *
* @throws \InvalidArgumentException When command name given does not exist * @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])) { if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name)); throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
@ -386,7 +386,7 @@ class Application
if ($this->wantHelps) { if ($this->wantHelps) {
$this->wantHelps = false; $this->wantHelps = false;
$helpCommand = $this->getCommand('help'); $helpCommand = $this->get('help');
$helpCommand->setCommand($command); $helpCommand->setCommand($command);
return $helpCommand; return $helpCommand;
@ -402,7 +402,7 @@ class Application
* *
* @return Boolean true if the command exists, false otherwise * @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]); return isset($this->commands[$name]) || isset($this->aliases[$name]);
} }
@ -451,7 +451,7 @@ class Application
/** /**
* Finds a command by name or alias. * 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. * match if you give it an abbreviation of a name or alias.
* *
* @param string $name A command name or a command 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 * @throws \InvalidArgumentException When command name is incorrect or ambiguous
*/ */
public function findCommand($name) public function find($name)
{ {
// namespace // namespace
$namespace = ''; $namespace = '';
@ -481,7 +481,7 @@ class Application
$abbrevs = static::getAbbreviations($commands); $abbrevs = static::getAbbreviations($commands);
if (isset($abbrevs[$name]) && 1 == count($abbrevs[$name])) { 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) { 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]))); 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 * @return array An array of Command instances
*/ */
public function getCommands($namespace = null) public function all($namespace = null)
{ {
if (null === $namespace) { if (null === $namespace) {
return $this->commands; return $this->commands;
@ -566,7 +566,7 @@ class Application
*/ */
public function asText($namespace = null) 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(), ''); $messages = array($this->getHelp(), '');
if ($namespace) { if ($namespace) {
@ -607,7 +607,7 @@ class Application
*/ */
public function asXml($namespace = null, $asDom = false) 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 = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true; $dom->formatOutput = true;

View File

@ -236,9 +236,9 @@ class Command
* *
* @param string $name The option name * @param string $name The option name
* @param string $shortcut The shortcut (can be null) * @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 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 * @return Command The current instance
*/ */

View File

@ -37,7 +37,7 @@ class HelpCommand extends Command
$this $this
->setDefinition(array( ->setDefinition(array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), 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') ->setName('help')
->setAliases(array('?')) ->setAliases(array('?'))
@ -65,7 +65,7 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
if (null === $this->command) { 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')) { if ($input->getOption('xml')) {

View File

@ -33,7 +33,7 @@ class ListCommand extends Command
$this $this
->setDefinition(array( ->setDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), 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') ->setName('list')
->setDescription('Lists commands') ->setDescription('Lists commands')

View File

@ -88,7 +88,7 @@ class ArgvInput extends Input
$name = substr($token, 1); $name = substr($token, 1);
if (strlen($name) > 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) // an option with a value (with no space)
$this->addShortOption($name[0], substr($name, 1)); $this->addShortOption($name[0], substr($name, 1));
} else { } else {
@ -115,7 +115,7 @@ class ArgvInput extends Input
} }
$option = $this->definition->getOptionForShortcut($name[$i]); $option = $this->definition->getOptionForShortcut($name[$i]);
if ($option->acceptParameter()) { if ($option->acceptValue()) {
$this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1)); $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
break; break;
@ -190,7 +190,7 @@ class ArgvInput extends Input
$option = $this->definition->getOption($name); $option = $this->definition->getOption($name);
if (null === $value && $option->acceptParameter()) { if (null === $value && $option->acceptValue()) {
// if option accepts an optional or mandatory argument // if option accepts an optional or mandatory argument
// let's see if there is one provided // let's see if there is one provided
$next = array_shift($this->parsed); $next = array_shift($this->parsed);
@ -202,11 +202,11 @@ class ArgvInput extends Input
} }
if (null === $value) { if (null === $value) {
if ($option->isParameterRequired()) { if ($option->isValueRequired()) {
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name)); 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; $this->options[$name] = $value;

View File

@ -133,11 +133,11 @@ class ArrayInput extends Input
$option = $this->definition->getOption($name); $option = $this->definition->getOption($name);
if (null === $value) { if (null === $value) {
if ($option->isParameterRequired()) { if ($option->isValueRequired()) {
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name)); 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; $this->options[$name] = $value;

View File

@ -18,7 +18,7 @@ namespace Symfony\Component\Console\Input;
* *
* $definition = new InputDefinition(array( * $definition = new InputDefinition(array(
* new InputArgument('name', InputArgument::REQUIRED), * 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> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
@ -347,7 +347,7 @@ class InputDefinition
$elements = array(); $elements = array();
foreach ($this->getOptions() as $option) { foreach ($this->getOptions() as $option) {
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : ''; $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) { foreach ($this->getArguments() as $argument) {
@ -399,7 +399,7 @@ class InputDefinition
$text[] = '<comment>Options:</comment>'; $text[] = '<comment>Options:</comment>';
foreach ($this->getOptions() as $option) { 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()); $default = sprintf('<comment> (default: %s)</comment>', is_array($option->getDefault()) ? str_replace("\n", '', print_r($option->getDefault(), true)): $option->getDefault());
} else { } else {
$default = ''; $default = '';
@ -450,13 +450,13 @@ class InputDefinition
$optionsXML->appendChild($optionXML = $dom->createElement('option')); $optionsXML->appendChild($optionXML = $dom->createElement('option'));
$optionXML->setAttribute('name', '--'.$option->getName()); $optionXML->setAttribute('name', '--'.$option->getName());
$optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : ''); $optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
$optionXML->setAttribute('accept_parameter', $option->acceptParameter() ? 1 : 0); $optionXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
$optionXML->setAttribute('is_parameter_required', $option->isParameterRequired() ? 1 : 0); $optionXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
$optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0); $optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
$optionXML->appendChild($descriptionXML = $dom->createElement('description')); $optionXML->appendChild($descriptionXML = $dom->createElement('description'));
$descriptionXML->appendChild($dom->createTextNode($option->getDescription())); $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
if ($option->acceptParameter()) { if ($option->acceptValue()) {
$optionXML->appendChild($defaultsXML = $dom->createElement('defaults')); $optionXML->appendChild($defaultsXML = $dom->createElement('defaults'));
$defaults = is_array($option->getDefault()) ? $option->getDefault() : ($option->getDefault() ? array($option->getDefault()) : array()); $defaults = is_array($option->getDefault()) ? $option->getDefault() : ($option->getDefault() ? array($option->getDefault()) : array());
foreach ($defaults as $default) { foreach ($defaults as $default) {

View File

@ -18,10 +18,10 @@ namespace Symfony\Component\Console\Input;
*/ */
class InputOption class InputOption
{ {
const PARAMETER_NONE = 1; const VALUE_NONE = 1;
const PARAMETER_REQUIRED = 2; const VALUE_REQUIRED = 2;
const PARAMETER_OPTIONAL = 4; const VALUE_OPTIONAL = 4;
const PARAMETER_IS_ARRAY = 8; const VALUE_IS_ARRAY = 8;
protected $name; protected $name;
protected $shortcut; protected $shortcut;
@ -34,9 +34,9 @@ class InputOption
* *
* @param string $name The option name * @param string $name The option name
* @param string $shortcut The shortcut (can be null) * @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 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 * @throws \InvalidArgumentException If option mode is invalid or incompatible
*/ */
@ -57,7 +57,7 @@ class InputOption
} }
if (null === $mode) { if (null === $mode) {
$mode = self::PARAMETER_NONE; $mode = self::VALUE_NONE;
} else if (!is_int($mode) || $mode > 15) { } else if (!is_int($mode) || $mode > 15) {
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode)); throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
} }
@ -67,8 +67,8 @@ class InputOption
$this->mode = $mode; $this->mode = $mode;
$this->description = $description; $this->description = $description;
if ($this->isArray() && !$this->acceptParameter()) { if ($this->isArray() && !$this->acceptValue()) {
throw new \InvalidArgumentException('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.'); throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
} }
$this->setDefault($default); $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. * 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() 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) public function setDefault($default = null)
{ {
if (self::PARAMETER_NONE === (self::PARAMETER_NONE & $this->mode) && null !== $default) { if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::PARAMETER_NONE mode.'); throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
} }
if ($this->isArray()) { if ($this->isArray()) {
@ -153,7 +153,7 @@ class InputOption
} }
} }
$this->default = $this->acceptParameter() ? $default : false; $this->default = $this->acceptValue() ? $default : false;
} }
/** /**

View File

@ -97,7 +97,7 @@ class Shell
// task name? // task name?
if (false === strpos($text, ' ') || !$text) { if (false === strpos($text, ' ') || !$text) {
return array_keys($this->application->getCommands()); return array_keys($this->application->all());
} }
// options and arguments? // options and arguments?