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;
    }
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;
    }
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 ; }
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()
Adds a command option to the builder .