The command names and command options determine which command is executed. In the example below, the console arguments contain the command name "server" and the command option "delete": $ console server --delete localhost $ console server -d localhost The last part "localhost" is the argument to the "server --delete" command.
Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
Inheritance: extends AbstractOption
 /**
  * Creates an input option for the given command option.
  *
  * @param CommandOption $commandOption The command option.
  *
  * @return InputOption The created input option.
  */
 private function adaptCommandOption(CommandOption $commandOption)
 {
     return new InputOption($commandOption->getLongName(), $commandOption->getShortName());
 }
示例#2
0
 /**
  * Adds a command option to the builder.
  *
  * The existing command options stored in the builder are preserved.
  *
  * @param CommandOption $commandOption The command option to add.
  *
  * @return static The current instance.
  *
  * @throws CannotAddOptionException If the option cannot be added.
  *
  * @see addCommandOptions()
  */
 public function addCommandOption(CommandOption $commandOption)
 {
     $longName = $commandOption->getLongName();
     $shortName = $commandOption->getShortName();
     $longAliases = $commandOption->getLongAliases();
     $shortAliases = $commandOption->getShortAliases();
     if ($this->hasOption($longName) || $this->hasCommandOption($longName)) {
         throw CannotAddOptionException::existsAlready($longName);
     }
     foreach ($longAliases as $shortAlias) {
         if ($this->hasOption($shortAlias) || $this->hasCommandOption($shortAlias)) {
             throw CannotAddOptionException::existsAlready($shortAlias);
         }
     }
     if ($shortName && ($this->hasOption($shortName) || $this->hasCommandOption($shortName))) {
         throw CannotAddOptionException::existsAlready($shortName);
     }
     foreach ($shortAliases as $shortAlias) {
         if ($this->hasOption($shortAlias) || $this->hasCommandOption($shortAlias)) {
             throw CannotAddOptionException::existsAlready($shortAlias);
         }
     }
     $this->commandOptions[$longName] = $commandOption;
     if ($shortName) {
         $this->commandOptionsByShortName[$shortName] = $commandOption;
     }
     foreach ($longAliases as $longAlias) {
         $this->commandOptions[$longAlias] = $commandOption;
     }
     foreach ($shortAliases as $shortAlias) {
         $this->commandOptionsByShortName[$shortAlias] = $commandOption;
     }
     return $this;
 }
示例#3
0
 /**
  * @dataProvider getValidAliases
  */
 public function testValidAliases($alias, array $longAliases, array $shortAliases)
 {
     $option = new CommandOption('delete', null, array($alias));
     $this->assertSame($longAliases, $option->getLongAliases());
     $this->assertSame($shortAliases, $option->getShortAliases());
 }