From 6f43cead463092c1d20ee55422481ecb913b87e4 Mon Sep 17 00:00:00 2001 From: Tim Goudriaan Date: Sat, 15 Dec 2018 00:56:37 +0100 Subject: [PATCH 1/2] [Console] Fix help text for single command applications --- Application.php | 10 +++++++++- Command/Command.php | 3 ++- Tests/Command/CommandTest.php | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Application.php b/Application.php index 680036041..b90b03ece 100644 --- a/Application.php +++ b/Application.php @@ -74,7 +74,7 @@ class Application private $dispatcher; private $terminal; private $defaultCommand; - private $singleCommand; + private $singleCommand = false; private $initialized; /** @@ -1162,6 +1162,14 @@ public function setDefaultCommand($commandName, $isSingleCommand = false) return $this; } + /** + * @internal + */ + public function isSingleCommand() + { + return $this->singleCommand; + } + private function splitStringByWidth($string, $width) { // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly. diff --git a/Command/Command.php b/Command/Command.php index d15dce3ab..cd9db7603 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -533,6 +533,7 @@ public function getHelp() public function getProcessedHelp() { $name = $this->name; + $isSingleCommand = $this->application && $this->application->isSingleCommand(); $placeholders = array( '%command.name%', @@ -540,7 +541,7 @@ public function getProcessedHelp() ); $replacements = array( $name, - $_SERVER['PHP_SELF'].' '.$name, + $isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].' '.$name, ); return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription()); diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index 6bc3f75b9..09c89c416 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -166,6 +166,14 @@ public function testGetProcessedHelp() $command = new \TestCommand(); $command->setHelp(''); $this->assertContains('description', $command->getProcessedHelp(), '->getProcessedHelp() falls back to the description'); + + $command = new \TestCommand(); + $command->setHelp('The %command.name% command does... Example: php %command.full_name%.'); + $application = new Application(); + $application->add($command); + $application->setDefaultCommand('namespace:name', true); + $this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly in single command applications'); + $this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name% in single command applications'); } public function testGetSetAliases() From 5917eb4c2f661194d38b9cd6d6e3d5a581dbe8cd Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 1 Jan 2019 14:42:07 +0100 Subject: [PATCH 2/2] update year in license files --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 21d7fb9e2..a677f4376 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2018 Fabien Potencier +Copyright (c) 2004-2019 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal