@@ -247,8 +247,8 @@ optionally accepts a value, but it's a bit tricky. Consider this example::
247247 )
248248 ;
249249
250- This option can be used in 3 ways: ``--yell ``, ``yell=louder ``, and not passing
251- the option at all . However, it's hard to distinguish between passing the option
250+ This option can be used in 3 ways: ``greet --yell ``, ``greet yell=louder ``,
251+ and `` greet `` . However, it's hard to distinguish between passing the option
252252without a value (``greet --yell ``) and not passing the option (``greet ``).
253253
254254To solve this issue, you have to set the option's default value to ``false ``::
@@ -267,7 +267,31 @@ To solve this issue, you have to set the option's default value to ``false``::
267267 )
268268 ;
269269
270- Now check the value of the option and keep in mind that ``false !== null ``::
270+ Now it's possible to differentiate between not passing the option and not
271+ passing any value for it::
272+
273+ $optionValue = $input->getOption('yell');
274+ if (false === $optionValue) {
275+ // in this case, the option was not passed when running the command
276+ $yell = false;
277+ $yellLouder = false;
278+ } elseif (null === $optionValue) {
279+ // in this case, the option was passed when running the command
280+ // but no value was given to it
281+ $yell = true;
282+ $yellLouder = false;
283+ } else {
284+ // in this case, the option was passed when running the command and
285+ // some specific value was given to it
286+ $yell = true;
287+ if ('louder' === $optionValue) {
288+ $yellLouder = true;
289+ } else {
290+ $yellLouder = false;
291+ }
292+ }
293+
294+ The above code can be simplified as follows because ``false !== null ``::
271295
272296 $optionValue = $input->getOption('yell');
273297 $yell = ($optionValue !== false);
0 commit comments