8000 [Console] Made output docopt compatible by wouterj · Pull Request #13220 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Made output docopt compatible #13220

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test for multiline descriptions
  • Loading branch information
wouterj committed Feb 18, 2015
commit 749d9cfba65fdcf81301473200f7f55b7f724e31
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function getInputArgumentData(InputArgument $argument)
'name' => $argument->getName(),
'is_required' => $argument->isRequired(),
'is_array' => $argument->isArray(),
'description' => $argument->getDescription(),
'description' => preg_replace('/\s*\R\s*/', ' ', $argument->getDescription()),
'default' => $argument->getDefault(),
);
}
Expand All @@ -120,7 +120,7 @@ private function getInputOptionData(InputOption $option)
'accept_value' => $option->acceptValue(),
'is_value_required' => $option->isValueRequired(),
'is_multiple' => $option->isArray(),
'description' => $option->getDescription(),
'description' => preg_replace('/\s*\R\s*/', ' ', $option->getDescription()),
'default' => $option->getDefault(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function describeInputArgument(InputArgument $argument, array $options
.'* Name: '.($argument->getName() ?: '<none>')."\n"
.'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
.'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
.'* Description: '.($argument->getDescription() ?: '<none>')."\n"
.'* Description: '.preg_replace('/\s*\R\s*/', PHP_EOL.' ', $argument->getDescription() ?: '<none>')."\n"
.'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
);
}
Expand All @@ -53,7 +53,7 @@ protected function describeInputOption(InputOption $option, array $options = arr
.'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
.'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
.'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
.'* Description: '.($option->getDescription() ?: '<none>')."\n"
.'* Description: '.preg_replace('/\s*\R\s*/', PHP_EOL.' ', $option->getDescription() ?: '<none>')."\n"
.'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected function describeInputArgument(InputArgument $argument, array $options
$this->writeText(sprintf(" <info>%s</info>%s%s%s",
$argument->getName(),
str_repeat(' ', $spacingWidth),
str_replace("\n", "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*\R\s*/', PHP_EOL.str_repeat(' ', $totalWidth + 17), $argument->getDescription()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional lines only need to have +4 spaces as the <info></info> elements only apply to the first line and that's catered for in the sprintf.

$default
), $options);
}
Expand Down Expand Up @@ -79,7 +80,8 @@ protected function describeInputOption(InputOption $option, array $options = arr
$this->writeText(sprintf(" <info>%s</info>%s%s%s%s",
$synopsis,
str_repeat(' ', $spacingWidth),
str_replace("\n", "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*\R\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional lines only need to have +4 spaces as the <info></info> elements only apply to the first line and that's catered for in the sprintf.

$default,
$option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
), $options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function getInputArguments()
'input_argument_1' => new InputArgument('argument_name', InputArgument::REQUIRED),
'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_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
);
}

Expand All @@ -40,6 +41,7 @@ public static function getInputOptions()
'input_option_2' => new InputOption('option_name', 'o', InputOption::VALUE_OPTIONAL, 'option description', 'default_value'),
'input_option_3' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description'),
'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"),
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"argument_name","is_required":true,"is_array":false,"description":"multiline argument description","default":null}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**argument_name:**

* Name: argument_name
* Is required: yes
* Is array: no
* Description: multiline
argument description
* Default: `NULL`
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<info>argument_name</info> multiline
argument description
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<argument name="argument_name" is_required="1" is_array="0">
<description>multiline
argument description</description>
<defaults/>
</argument>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"multiline option description","default":null}
10 changes: 10 additions & 0 deletions src/Symfony/Component/Console/Tests/Fixtures/input_option_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**option_name:**

* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: multiline
option description
* Default: `NULL`
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<info>-o, --option_name=OPTION_NAME</info> multiline
option description
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="0">
<description>multiline
option description</description>
<defaults/>
</option>
0