-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Negatable options can contradict each other #304
Comments
I've raised a potential change as pull-request #305 It switches to the approach using by Symfony Console. However, an input option with a type of One challenge is that the Another approach might be to add a separate |
One very important aspect here is that we need our options to have a default value. Without a default value, then you cannot set option values with config. I thought that the Symfony Console negatable option allowed for this, but I have not investigated or tried your PR yet. Regarding your report, if your option is defined as |
Here are the relevant Symfony Console https://github.com/symfony/console/blob/7.0/Input/InputOption.php#L113C1-L115C10 if ($this->isNegatable() && $this->acceptValue()) {
throw new InvalidArgumentException('Impossible to have an option mode VALUE_NEGATABLE if the option also accepts a value.');
} https://github.com/symfony/console/blob/7.0/Input/InputOption.php#L181 if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
} Negatable options are always expected to be used without a value, either With a negatable option, if neither This behaviour can be useful when the developer wishes to detect if an option has been explicitly set, but does mean the mechanism of providing a default value isn't available , and the developer would have to explicitly check for NULL and then apply a value programmatically. |
Very unfortunate. I explained the need for binary options to be able to accept a default value when I submitted the original PR for that feature. Sounds like the explanation was lost at some point in the ensuing years. |
Context
Symfony Console and Annotated Command support negateable options. An example can be found in the Drush
cache:rebuild
command which offers the--cache-clear
and--no-cache-clear
options.Negateable options are expected to be in balance, if
--cache-clear
is set (and therefore TRUE), then--no-cache-clear
should be FALSE.The options documentation describes the behaviour where a default of
true
is providedhttps://github.com/consolidation/annotated-command#option-default-values
Steps to reproduce
--help
output demonstrates a--foo
and a--no-foo
option.--no-foo
parameter.Expected behavior
Tell us what should happen
--no-foo
(acquired using$input->getOption()
) should be set to TRUE.--foo
(acquired using$input->getOption()
) should be set to FALSE.Actual behavior
Tell us what happens instead
--no-foo
(acquired using$input->getOption()
) is set to TRUE.--foo
(acquired using$input->getOption()
) is also set to TRUE.System Configuration
Which O.S. and PHP version are you using?
The text was updated successfully, but these errors were encountered: