addCommandOption() public method

The existing command options stored in the builder are preserved.
See also: addCommandOptions()
public addCommandOption ( CommandOption $commandOption ) : static
$commandOption CommandOption The command option to add.
return static The current instance.
 /**
  * @expectedException \Webmozart\Console\Api\Args\CannotAddOptionException
  */
 public function testFailIfAddingOptionWithSameShortNameAsCommandOptionAlias()
 {
     $this->builder->addCommandOption(new CommandOption('option1', 'o', array('a')));
     $this->builder->addOption(new Option('option2', 'a'));
 }
Esempio n. 2
0
 /**
  * Creates a format builder for a set of arguments and options.
  *
  * @param array      $elements   The arguments and options to add to the
  *                               builder.
  * @param ArgsFormat $baseFormat The base format.
  *
  * @return ArgsFormatBuilder The created builder.
  */
 private function createBuilderForElements(array $elements, ArgsFormat $baseFormat = null)
 {
     $builder = new ArgsFormatBuilder($baseFormat);
     foreach ($elements as $element) {
         if ($element instanceof CommandName) {
             $builder->addCommandName($element);
         } elseif ($element instanceof CommandOption) {
             $builder->addCommandOption($element);
         } elseif ($element instanceof Option) {
             $builder->addOption($element);
         } elseif ($element instanceof Argument) {
             $builder->addArgument($element);
         } else {
             throw new InvalidArgumentException(sprintf('Expected instances of CommandName, CommandOption, ' . 'Option or Argument. Got: %s', is_object($element) ? get_class($element) : gettype($element)));
         }
     }
     return $builder;
 }