[Console] Escape default value when dumping help
This commit is contained in:
parent
7e8e9e3a6e
commit
c24269005b
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Descriptor;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||||
use Symfony\Component\Console\Helper\Helper;
|
use Symfony\Component\Console\Helper\Helper;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputDefinition;
|
use Symfony\Component\Console\Input\InputDefinition;
|
||||||
@ -236,6 +237,16 @@ class TextDescriptor extends Descriptor
|
|||||||
*/
|
*/
|
||||||
private function formatDefaultValue($default)
|
private function formatDefaultValue($default)
|
||||||
{
|
{
|
||||||
|
if (is_string($default)) {
|
||||||
|
$default = OutputFormatter::escape($default);
|
||||||
|
} elseif (is_array($default)) {
|
||||||
|
foreach ($default as $key => $value) {
|
||||||
|
if (is_string($value)) {
|
||||||
|
$default[$key] = OutputFormatter::escape($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (PHP_VERSION_ID < 50400) {
|
if (PHP_VERSION_ID < 50400) {
|
||||||
return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default));
|
return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default));
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ class ObjectsProvider
|
|||||||
'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'),
|
'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'),
|
||||||
'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'),
|
'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'),
|
||||||
'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
|
'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
|
||||||
|
'input_argument_with_style' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', '<comment>style</>'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,6 +44,8 @@ class ObjectsProvider
|
|||||||
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
|
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
|
||||||
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
|
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
|
||||||
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
|
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
|
||||||
|
'input_option_with_style' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description', '<comment>style</>'),
|
||||||
|
'input_option_with_style_array' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'option description', array('<comment>Hello</comment>', '<info>world</info>')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "argument_name",
|
||||||
|
"is_required": false,
|
||||||
|
"is_array": false,
|
||||||
|
"description": "argument description",
|
||||||
|
"default": "<comment>style</>"
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
**argument_name:**
|
||||||
|
|
||||||
|
* Name: argument_name
|
||||||
|
* Is required: no
|
||||||
|
* Is array: no
|
||||||
|
* Description: argument description
|
||||||
|
* Default: `'<comment>style</>'`
|
@ -0,0 +1 @@
|
|||||||
|
<info>argument_name</info> argument description<comment> [default: "\<comment>style\</>"]</comment>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<argument name="argument_name" is_required="0" is_array="0">
|
||||||
|
<description>argument description</description>
|
||||||
|
<defaults>
|
||||||
|
<default><comment>style</></default>
|
||||||
|
</defaults>
|
||||||
|
</argument>
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "--option_name",
|
||||||
|
"shortcut": "-o",
|
||||||
|
"accept_value": true,
|
||||||
|
"is_value_required": true,
|
||||||
|
"is_multiple": false,
|
||||||
|
"description": "option description",
|
||||||
|
"default": "<comment>style</>"
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
**option_name:**
|
||||||
|
|
||||||
|
* Name: `--option_name`
|
||||||
|
* Shortcut: `-o`
|
||||||
|
* Accept value: yes
|
||||||
|
* Is value required: yes
|
||||||
|
* Is multiple: no
|
||||||
|
* Description: option description
|
||||||
|
* Default: `'<comment>style</>'`
|
@ -0,0 +1 @@
|
|||||||
|
<info>-o, --option_name=OPTION_NAME</info> option description<comment> [default: "\<comment>style\</>"]</comment>
|
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="0">
|
||||||
|
<description>option description</description>
|
||||||
|
<defaults>
|
||||||
|
<default><comment>style</></default>
|
||||||
|
</defaults>
|
||||||
|
</option>
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "--option_name",
|
||||||
|
"shortcut": "-o",
|
||||||
|
"accept_value": true,
|
||||||
|
"is_value_required": true,
|
||||||
|
"is_multiple": true,
|
||||||
|
"description": "option description",
|
||||||
|
"default": [
|
||||||
|
"<comment>Hello</comment>",
|
||||||
|
"<info>world</info>"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
**option_name:**
|
||||||
|
|
||||||
|
* Name: `--option_name`
|
||||||
|
* Shortcut: `-o`
|
||||||
|
* Accept value: yes
|
||||||
|
* Is value required: yes
|
||||||
|
* Is multiple: yes
|
||||||
|
* Description: option description
|
||||||
|
* Default: `array ( 0 => '<comment>Hello</comment>', 1 => '<info>world</info>',)`
|
@ -0,0 +1 @@
|
|||||||
|
<info>-o, --option_name=OPTION_NAME</info> option description<comment> [default: ["\<comment>Hello\</comment>","\<info>world\</info>"]]</comment><comment> (multiple values allowed)</comment>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="1">
|
||||||
|
<description>option description</description>
|
||||||
|
<defaults>
|
||||||
|
<default><comment>Hello</comment></default>
|
||||||
|
<default><info>world</info></default>
|
||||||
|
</defaults>
|
||||||
|
</option>
|
Reference in New Issue
Block a user