Ejemplo n.º 1
0
 public function testCreateWithAliasesDashes()
 {
     $option = new CommandOption('delete', null, array('--alias', '-a', '-A'));
     $this->assertSame('delete', $option->getLongName());
     $this->assertNull($option->getShortName());
     $this->assertSame(array('alias'), $option->getLongAliases());
     $this->assertSame(array('a', 'A'), $option->getShortAliases());
     $this->assertNull($option->getDescription());
     $this->assertTrue($option->isLongNamePreferred());
     $this->assertFalse($option->isShortNamePreferred());
 }
Ejemplo n.º 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;
 }
 /**
  * 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());
 }