diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php
index 403b7db..800dd09 100644
--- a/Mage/Command/AbstractCommand.php
+++ b/Mage/Command/AbstractCommand.php
@@ -29,6 +29,7 @@ abstract class AbstractCommand
private $helpMessage;
private $usageExamples = [];
private $syntaxMessage;
+ private $name;
/**
* Runs the Command
@@ -57,6 +58,13 @@ abstract class AbstractCommand
return $this->config;
}
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
public function setHelpMessage($message)
{
$this->helpMessage = $message;
@@ -83,10 +91,15 @@ abstract class AbstractCommand
$indent = str_repeat(" ", 4);
$output = "";
+ if (!empty($this->name)) {
+ $output .= "\n";
+ $output .= "Command: ";
+ $output .= $this->name;
+ }
if (!empty($this->helpMessage)) {
$output .= "\n";
- $output .= "{$this->helpMessage}\n";
+ $output .= "{$this->helpMessage}\n";
}
if (!empty($this->syntaxMessage)) {
diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php
index ebf5af7..877dfae 100644
--- a/tests/MageTest/Command/AbstractCommandTest.php
+++ b/tests/MageTest/Command/AbstractCommandTest.php
@@ -49,6 +49,7 @@ class AbstractCommandTest extends BaseTest
{
return [
'happy_path' => [
+ 'name' => 'Example command',
'helpMessage' => 'This command does everything you want to',
'examples' => [
[
@@ -62,7 +63,8 @@ class AbstractCommandTest extends BaseTest
],
'syntax' => 'mage example [light]',
'output' => "\n"
- . "This command does everything you want to\n"
+ . "Command: Example command\n"
+ . "This command does everything you want to\n"
. "\n"
. "Syntax:\n"
. " mage example [light]\n"
@@ -74,6 +76,7 @@ class AbstractCommandTest extends BaseTest
. " mage example light\n"
],
'no_help_message' => [
+ 'name' => 'Example command',
'helpMessage' => '',
'examples' => [
[
@@ -87,6 +90,7 @@ class AbstractCommandTest extends BaseTest
],
'syntax' => 'mage example [light]',
'output' => "\n"
+ . "Command: Example command\n"
. "Syntax:\n"
. " mage example [light]\n"
. "\n"
@@ -97,16 +101,19 @@ class AbstractCommandTest extends BaseTest
. " mage example light\n"
],
'no_examples' => [
+ 'name' => 'Example command',
'helpMessage' => 'This command does everything you want to',
'examples' => [],
'syntax' => 'mage example [light]',
'output' => "\n"
- . "This command does everything you want to\n"
+ . "Command: Example command\n"
+ . "This command does everything you want to\n"
. "\n"
. "Syntax:\n"
. " mage example [light]\n"
],
"no_syntax" => [
+ 'name' => 'Example command',
'helpMessage' => 'This command does everything you want to',
'examples' => [
[
@@ -120,7 +127,8 @@ class AbstractCommandTest extends BaseTest
],
'syntax' => '',
'output' => "\n"
- . "This command does everything you want to\n"
+ . "Command: Example command\n"
+ . "This command does everything you want to\n"
. "\n"
. "Usage examples:\n"
. " * Default command:\n"
@@ -129,20 +137,22 @@ class AbstractCommandTest extends BaseTest
. " mage example light\n"
],
"stripping_colons" => [
+ 'name' => 'Example command',
'helpMessage' => 'This command does everything you want to',
'examples' => [
[
'snippet' => 'mage example',
- 'description' => 'Default command:'
+ 'description' => 'Default command : '
],
[
'snippet' => 'mage example light',
- 'description' => 'Runs the command with lights:'
+ 'description' => 'Runs the command with lights: '
]
],
'syntax' => 'mage example [light]',
'output' => "\n"
- . "This command does everything you want to\n"
+ . "Command: Example command\n"
+ . "This command does everything you want to\n"
. "\n"
. "Syntax:\n"
. " mage example [light]\n"
@@ -154,13 +164,16 @@ class AbstractCommandTest extends BaseTest
. " mage example light\n"
],
"only_help" => [
+ 'name' => 'Example command',
'helpMessage' => 'This command does everything you want to',
'examples' => [],
'syntax' => '',
'output' => "\n"
- . "This command does everything you want to\n"
+ . "Command: Example command\n"
+ . "This command does everything you want to\n"
],
"only_examples" => [
+ 'name' => 'Example command',
'helpMessage' => '',
'examples' => [
[
@@ -174,6 +187,7 @@ class AbstractCommandTest extends BaseTest
],
'syntax' => '',
'output' => "\n"
+ . "Command: Example command\n"
. "Usage examples:\n"
. " * Default command:\n"
. " mage example\n"
@@ -181,12 +195,40 @@ class AbstractCommandTest extends BaseTest
. " mage example light\n"
],
"only_syntax" => [
+ 'name' => 'Example command',
'helpMessage' => '',
'examples' => [],
'syntax' => 'mage example [light]',
'output' => "\n"
+ . "Command: Example command\n"
. "Syntax:\n"
. " mage example [light]\n"
+ ],
+ "no_name" => [
+ 'name' => '',
+ 'helpMessage' => 'This command does everything you want to',
+ 'examples' => [
+ [
+ 'snippet' => 'mage example',
+ 'description' => 'Default command'
+ ],
+ [
+ 'snippet' => 'mage example light',
+ 'description' => 'Runs the command with lights'
+ ]
+ ],
+ 'syntax' => 'mage example [light]',
+ 'output' => "\n"
+ . "This command does everything you want to\n"
+ . "\n"
+ . "Syntax:\n"
+ . " mage example [light]\n"
+ . "\n"
+ . "Usage examples:\n"
+ . " * Default command:\n"
+ . " mage example\n"
+ . " * Runs the command with lights:\n"
+ . " mage example light\n"
]
];
}
@@ -199,11 +241,13 @@ class AbstractCommandTest extends BaseTest
*
* @dataProvider infoMessageProvider
*/
- public function testGetInfoMessage($helpMessage, $examples, $syntax, $expectedMessage)
+ public function testGetInfoMessage($name, $helpMessage, $examples, $syntax, $expectedMessage)
{
/** @var AbstractCommand $command */
$command = $this->getMockForAbstractClass('Mage\Command\AbstractCommand');
+ $command->setName($name);
+
foreach ($examples as $example) {
$command->addUsageExample($example['snippet'], $example['description']);
}