private function addOption($string, $value)
    {
        foreach ($this->optionList as $option) {
            if ($option->matches($string)) {
                if ($option->mode() == Getopt::IS_FLAG) {
                    if (is_null($value)) {
                        $value = isset($this->options[$string]) ?
                            !$this->options[$string]->getValue() :
                ($option->getArgument()->hasDefaultValue() ?
                            !$option->getArgument()->getDefaultValue() : true);
                    }
                } else {
                    if ($option->mode() == Getopt::REQUIRED_ARGUMENT && !mb_strlen($value)) {
                        throw new \UnexpectedValueException("Option '$string' must have a value");
                    }
                    if ($option->getArgument()->hasValidation()) {
                        if ((mb_strlen($value) > 0) && !$option->getArgument()->validates($value)) {
                            throw new \UnexpectedValueException("Option '$string' has an invalid value");
                        }
                    }
                // for no-argument options, check if they are duplicate
                if ($option->mode() == Getopt::NO_ARGUMENT) {
                    $oldValue = isset($this->options[$string]) ?
                        $this->options[$string]->getValue() : null;
                    $value = is_null($oldValue) ? 1 : $oldValue + 1;
                }
                // for optional-argument options, set value to 1 if none was given
                $value = (mb_strlen($value) > 0) ? $value : 1;
                }
                // add both long and short names (if they exist) to the option array to facilitate lookup
                if ($option->short()) {
                    $this->options[$option->short()] = new Value($value);
                }
                if ($option->long()) {
                    $this->options[$option->long()] = new Value($value);
                }

                return;
            }
        }
        throw new \UnexpectedValueException("Option '$string' is unknown");
    }