Description
If you have ...
->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'The file', 'C:\folder\file.ext');
when you run with --help
, you get ...
-f, --file=FILE The file. [default: "C:\\folder\\file.ext"]
The double backslash is incorrect.
NOTE: The default value is coming from a .env file and the value is specific to the user using the code and they are on OSx, Unix or Windows. But, if a user types this at the command line, it will be incorrect with the double backslash.
According to https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Console/Descriptor/TextDescriptor.php#L242, outputting the JSON value rather than the literal value into the help would seem to be incorrect as it may not be appropriate in all circumstances (say the literal is NOT a filename but something else).
As TextDescriptor::formatDefaultValue()
in its current form (i.e. using json_encode()
rather than var_export()
) was introduced to fix bug #4193, I think the consideration of showing escaped backslashes was not considered.
Now whilst escaping backslashes is normally correct (and certainly is for JSON), it really isn't appropriate for text that represents a default value that a user will type at the command line.