Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7058f55

Browse filesBrowse files
codedmonkeyRobin Chalas
authored and
Robin Chalas
committed
[Console] Fix help text for single command applications
1 parent f82beb5 commit 7058f55
Copy full SHA for 7058f55

File tree

Expand file treeCollapse file tree

3 files changed

+19
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+19
-2
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Application
7474
private $dispatcher;
7575
private $terminal;
7676
private $defaultCommand;
77-
private $singleCommand;
77+
private $singleCommand = false;
7878
private $initialized;
7979

8080
/**
@@ -1162,6 +1162,14 @@ public function setDefaultCommand($commandName, $isSingleCommand = false)
11621162
return $this;
11631163
}
11641164

1165+
/**
1166+
* @internal
1167+
*/
1168+
public function isSingleCommand()
1169+
{
1170+
return $this->singleCommand;
1171+
}
1172+
11651173
private function splitStringByWidth($string, $width)
11661174
{
11671175
// str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.

‎src/Symfony/Component/Console/Command/Command.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,15 @@ public function getHelp()
533533
public function getProcessedHelp()
534534
{
535535
$name = $this->name;
536+
$isSingleCommand = $this->application && $this->application->isSingleCommand();
536537

537538
$placeholders = array(
538539
'%command.name%',
539540
'%command.full_name%',
540541
);
541542
$replacements = array(
542543
$name,
543-
$_SERVER['PHP_SELF'].' '.$name,
544+
$isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].' '.$name,
544545
);
545546

546547
return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());

‎src/Symfony/Component/Console/Tests/Command/CommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/CommandTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ public function testGetProcessedHelp()
166166
$command = new \TestCommand();
167167
$command->setHelp('');
168168
$this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description');
169+
170+
$command = new \TestCommand();
171+
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
172+
$application = new Application();
173+
$application->add($command);
174+
$application->setDefaultCommand('namespace:name', true);
175+
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly in single command applications');
176+
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name% in single command applications');
169177
}
170178

171179
public function testGetSetAliases()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.