Webmozart\Console\Api\Args\Format\ArgsFormatBuilder::getOption PHP Method

getOption() public method

Returns an option by its long or short name.
public getOption ( string $name, boolean $includeBase = true ) : Option
$name string The long or short option name.
$includeBase boolean Whether to include options in the base format in the search.
return Option The option.
    public function getOption($name, $includeBase = true)
    {
        Assert::string($name, 'The option name must be a string. Got: %s');
        Assert::notEmpty($name, 'The option name must not be empty.');
        Assert::boolean($includeBase, 'The parameter $includeBase must be a boolean. Got: %s');
        if (isset($this->options[$name])) {
            return $this->options[$name];
        }
        if (isset($this->optionsByShortName[$name])) {
            return $this->optionsByShortName[$name];
        }
        if ($includeBase && $this->baseFormat) {
            return $this->baseFormat->getOption($name);
        }
        throw NoSuchOptionException::forOptionName($name);
    }

Usage Example

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testGetOptionFailsIfIncludeBaseNoBoolean()
 {
     $this->builder->getOption('argument', 1234);
 }