8000 bug #15976 [Console] do not make the getHelp() method smart (xabbuh) · symfony/symfony@3f2e80f · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f2e80f

Browse files
committed
bug #15976 [Console] do not make the getHelp() method smart (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Console] do not make the getHelp() method smart | Q | A | ------------- | --- | Bug fix? | kind of | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | In my opinion, the way to always display a help message to the user was implemented in #15601 is not good enough. The getter method for the help should only return the actual value. Otherwise, user's would not have a way to check if a command really has a help message (for example, when building their own CLI applications or whatever). Instead, we should only return the description as a fallback of the help message when it is processed to present it to the user. Commits ------- cdf1f00 [Console] do not make the getHelp() method smart
2 parents 3765d8a + cdf1f00 commit 3f2e80f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public function setHelp($help)
491491
*/
492492
public function getHelp()
493493
{
494-
return $this->help ?: $this->description;
494+
return $this->help;
495495
}
496496

497497
/**
@@ -513,7 +513,7 @@ public function getProcessedHelp()
513513
$_SERVER['PHP_SELF'].' '.$name,
514514
);
515515

516-
return str_replace($placeholders, $replacements, $this->getHelp());
516+
return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());
517517
}
518518

519519
/**

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function testGetSetHelp()
132132
$this->assertEquals($command, $ret, '->setHelp() implements a fluent interface');
133133
$this->assertEquals('help1', $command->getHelp(), '->setHelp() sets the help');
134134
$command->setHelp('');
135-
$this->assertEquals('description', $command->getHelp(), '->getHelp() fallback to the description');
135+
$this->assertEquals('', $command->getHelp(), '->getHelp() does not fall back to the description');
136136
}
137137

138138
public function testGetProcessedHelp()
@@ -141,6 +141,10 @@ public function testGetProcessedHelp()
141141
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
142142
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly');
143143
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name%');
144+
145+
$command = new \TestCommand();
146+
$command->setHelp('');
147+
$this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description');
144148
}
145149

146150
public function testGetSetAliases()

0 commit comments

Comments
 (0)
0