-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Negatable option are null by default #40986
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this! It turns "negatable options" into tri-state options, which is something that was asked for by some developers. Thanks Jérémy!
7f27474
to
8df7fdd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change means that $this->getOption('ansi')
can now return null
, which is a BC break as it always returns a bool right now. Maybe we should have false
as a default for this internal flag (no need for 3 states here anyway).
The main difference is about "What's a negatable option?" (1) A single option with two behaviors (yes/no) In case (1), we need a tri-state to differentiate these cases: $useAnsi = $input->getOption('ansi');
if (true === $useAnsi) {
// force ANSI usage
} elseif (false === $useAnsi) {
// don't use ANSI
} elseif (null === $useAnsi) {
// user didn't pass any ANSI preference;
// we must decide what to do
} In case (2), you only need two cases (the third one happens automatically): $useAnsi = $input->getOption('ansi');
$dontUseAnsi = $input->getOption('no-ansi');
if ($useAnsi) {
// force ANSI usage
} elseif ($dontUseAnsi) {
// don't use ANSI
} else {
// user didn't pass any ANSI preference;
// we must decide what to do
} |
8df7fdd
to
22cb37c
Compare
The BC break has been solved by setting the default to
|
Thank you @jderusse. |
given the command
bin/console test --no-ansi
false
bin/console test --ansi
true
bin/console test
null