8000 [Console] More consistent application description · symfony/symfony@28edd30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28edd30

Browse files
secondtruthfabpot
authored andcommitted
[Console] More consistent application description
1 parent 4677e92 commit 28edd30

File tree

9 files changed

+85
-90
lines changed

9 files changed

+85
-90
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,24 +251,7 @@ public function getDefinition()
251251
*/
252252
public function getHelp()
253253
{
254-
$messages = array(
255-
$this->getLongVersion(),
256-
'',
257-
'<comment>Usage:</comment>',
258-
' [options] command [arguments]',
259-
'',
260-
'<comment>Options:</comment>',
261-
);
262-
263-
foreach ($this->getDefinition()->getOptions() as $option) {
264-
$messages[] = sprintf(' %-29s %s %s',
265-
'<info>--'.$option->getName().'</info>',
266-
$option->getShortcut() ? '<info>-'.$option->getShortcut().'</info>' : ' ',
267-
$option->getDescription()
268-
);
269-
}
270-
271-
return implode(PHP_EOL, $messages);
254+
return $this->getLongVersion();
272255
}
273256

274257
/**

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,34 @@ protected function describeApplication(Application $application, array $options
157157
$this->writeText("\n");
158158
}
159159
} else {
160-
$width = $this->getColumnWidth($description->getCommands());
160+
if ('' != $help = $application->getHelp()) {
161+
$this->writeText("$help\n\n", $options);
162+
}
163+
164+
$this->writeText("<comment>Usage:</comment>\n", $options);
165+
$this->writeText(" [options] command [arguments]\n\n", $options);
166+
$this->writeText('<comment>Options:</comment>', $options);
167+
168+
$inputOptions = $application->getDefinition()->getOptions();
169+
170+
$width = 0;
171+
foreach ($inputOptions as $option) {
172+
$nameLength = strlen($option->getName()) + 2;
173+
if ($option->getShortcut()) {
174+
$nameLength += strlen($option->getShortcut()) + 3;
175+
}
176+
$width = max($width, $nameLength);
177+
}
178+
++$width;
179+
180+
foreach ($inputOptions as $option) {
181+
$this->writeText("\n", $options);
182+
$this->describeInputOption($option, array_merge($options, array('name_width' => $width)));
183+
}
184+
185+
$this->writeText("\n\n", $options);
161186

162-
$this->writeText($application->getHelp(), $options);
163-
$this->writeText("\n\n");
187+
$width = $this->getColumnWidth($description->getCommands());
164188

165189
if ($describedNamespace) {
166190
$this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
@@ -177,7 +201,7 @@ protected function describeApplication(Application $application, array $options
177201

178202
foreach ($namespace['commands'] as $name) {
179203
$this->writeText("\n");
180-
$this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
204+
$this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
181205
}
182206
}
183207

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testGetLongVersion()
9595
public function testHelp()
9696
{
9797
$application = new Application();
98-
$this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $this->normalizeLineBreaks($application->getHelp()), '->setHelp() returns a help message');
98+
$this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $this->normalizeLineBreaks($application->getHelp()), '->getHelp() returns a help message');
9999
}
100100

101101
public function testAll()
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<info>Console Tool</info>
22

33
<comment>Usage:</comment>
4-
[options] command [arguments]
4+
[options] command [arguments]
55

66
<comment>Options:</comment>
7-
<info>--help</info> <info>-h</info> Display this help message.
8-
<info>--quiet</info> <info>-q</info> Do not output any message.
9-
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10-
<info>--version</info> <info>-V</info> Display this application version.
11-
<info>--ansi</info> Force ANSI output.
12-
<info>--no-ansi</info> Disable ANSI output.
13-
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
7+
<info>--help</info> (-h) Display this help message.
8+
<info>--quiet</info> (-q) Do not output any message.
9+
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10+
<info>--version</info> (-V) Display this application version.
11+
<info>--ansi</info> Force ANSI output.
12+
<info>--no-ansi</info> Disable ANSI output.
13+
<info>--no-interaction</info> (-n) Do not ask any interactive question.
1414

1515
<comment>Available commands:</comment>
16-
<info>help </info> Displays help for a command
17-
<info>list </info> Lists commands
16+
<info>help </info> Displays help for a command
17+
<info>list </info> Lists commands
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<info>My Symfony application</info> version <comment>v1.0</comment>
22

33
<comment>Usage:</comment>
4-
[options] command [arguments]
4+
[options] command [arguments]
55

66
<comment>Options:</comment>
7-
<info>--help</info> <info>-h</info> Display this help message.
8-
<info>--quiet</info> <info>-q</info> Do not output any message.
9-
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10-
<info>--version</info> <info>-V</info> Display this application version.
11-
<info>--ansi</info> Force ANSI output.
12-
<info>--no-ansi</info> Disable ANSI output.
13-
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
7+
<info>--help</info> (-h) Display this help message.
8+
<info>--quiet</info> (-q) Do not output any message.
9+
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10+
<info>--version</info> (-V) Display this application version.
11+
<info>--ansi</info> Force ANSI output.
12+
<info>--no-ansi</info> Disable ANSI output.
13+
<info>--no-interaction</info> (-n) Do not ask any interactive question.
1414

1515
<comment>Available commands:</comment>
16-
<info>alias1 </info> command 1 description
17-
<info>alias2 </info> command 1 description
18-
<info>help </info> Displays help for a command
19-
<info>list </info> Lists commands
16+
<info>alias1 </info> command 1 description
17+
<info>alias2 </info> command 1 description
18+
<info>help </info> Displays help for a command
19+
<info>list </info> Lists commands
2020
<comment>descriptor</comment>
21-
<info>descriptor:command1 </info> command 1 description
22-
<info>descriptor:command2 </info> command 2 description
21+
<info>descriptor:command1 </info> command 1 description
22+
<info>descriptor:command2 </info> command 2 description
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<info>Console Tool</info>
22

33
<comment>Usage:</comment>
4-
[options] command [arguments]
4+
[options] command [arguments]
55

66
<comment>Options:</comment>
7-
<info>--help</info> <info>-h</info> Display this help message.
8-
<info>--quiet</info> <info>-q</info> Do not output any message.
9-
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10-
<info>--version</info> <info>-V</info> Display this application version.
11-
<info>--ansi</info> Force ANSI output.
12-
<info>--no-ansi</info> Disable ANSI output.
13-
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
7+
<info>--help</info> (-h) Display this help message.
8+
<info>--quiet</info> (-q) Do not output any message.
9+
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10+
<info>--version</info> (-V) Display this application version.
11+
<info>--ansi</info> Force ANSI output.
12+
<info>--no-ansi</info> Disable ANSI output.
13+
<info>--no-interaction</info> (-n) Do not ask any interactive question.
1414

1515
<comment>Available commands:</comment>
16-
<info>afoobar </info> The foo:bar command
17-
<info>help </info> Displays help for a command
18-
<info>list </info> Lists commands
16+
<info>afoobar </info> The foo:bar command
17+
<info>help </info> Displays help for a command
18+
<info>list </info> Lists commands
1919
<comment>foo</comment>
20-
<info>foo:bar </info> The foo:bar command
20+
<info>foo:bar </info> The foo:bar command
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<info>Console Tool</info>
22

33
<comment>Usage:</comment>
4-
[options] command [arguments]
4+
[options] command [arguments]
55

66
<comment>Options:</comment>
7-
<info>--help</info> <info>-h</info> Display this help message.
8-
<info>--quiet</info> <info>-q</info> Do not output any message.
9-
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10-
<info>--version</info> <info>-V</info> Display this application version.
11-
<info>--ansi</info> Force ANSI output.
12-
<info>--no-ansi</info> Disable ANSI output.
13-
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
7+
<info>--help</info> (-h) Display this help message.
8+
<info>--quiet</info> (-q) Do not output any message.
9+
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10+
<info>--version</info> (-V) Display this application version.
11+
<info>--ansi</info> Force ANSI output.
12+
<info>--no-ansi</info> Disable ANSI output.
13+
<info>--no-interaction</info> (-n) Do not ask any interactive question.
1414

1515
<comment>Available commands for the "foo" namespace:</comment>
16-
<info>foo:bar </info> The foo:bar command
16+
<info>foo:bar </info> The foo:bar command
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
11
<info>Console Tool</info>
2-
3-
<comment>Usage:</comment>
4-
[options] command [arguments]
5-
6-
<comment>Options:</comment>
7-
<info>--help</info> <info>-h</info> Display this help message.
8-
<info>--quiet</info> <info>-q</info> Do not output any message.
9-
<info>--verbose</info> <info>-v|vv|vvv</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10-
<info>--version</info> <info>-V</info> Display this application version.
11-
<info>--ansi</info> Force ANSI output.
12-
<info>--no-ansi</info> Disable ANSI output.
13-
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
Console Tool
22

33
Usage:
4-
[options] command [arguments]
4+
[options] command [arguments]
55

66
Options:
7-
--help -h Display this help message.
8-
--quiet -q Do not output any message.
9-
--verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10-
--version -V Display this application version.
11-
--ansi Force ANSI output.
12-
--no-ansi Disable ANSI output.
13-
--no-interaction -n Do not ask any interactive question.
7+
--help (-h) Display this help message.
8+
--quiet (-q) Do not output any message.
9+
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
10+
--version (-V) Display this application version.
11+
--ansi Force ANSI output.
12+
--no-ansi Disable ANSI output.
13+
--no-interaction (-n) Do not ask any interactive question.
1414

1515
Available commands:
16-
help Displays help for a command
17-
list Lists commands
16+
help Displays help for a command
17+
list Lists commands

0 commit comments

Comments
 (0)
0