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 5c71d7b

Browse filesBrowse files
author
Robin Chalas
committed
bug #29617 [Console] Add specific replacement for help text in single command applications (codedmonkey)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Add specific replacement for help text in single command applications | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- required for new features --> Simply omits the command name in the help text of single command applications which was wrongly displayed before. For example, if the default command of an application is `echo` and the application is located at `bin/echo`, previously the help text would display `php bin/echo echo <text>` which is incorrect for single command applications since the command name ~~can~~ **must** be omitted: `php bin/echo <text>`. Commits ------- 7058f55 [Console] Fix help text for single command applications
2 parents f82beb5 + 7058f55 commit 5c71d7b
Copy full SHA for 5c71d7b

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.