mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	Add command name as an option
This commit is contained in:
		
							parent
							
								
									94d301f66f
								
							
						
					
					
						commit
						4e18ae1f8c
					
				@ -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 .= "<cyan><bold>Command: </bold></cyan>";
 | 
			
		||||
            $output .= $this->name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!empty($this->helpMessage)) {
 | 
			
		||||
            $output .= "\n";
 | 
			
		||||
            $output .= "<cyan><bold>{$this->helpMessage}</bold></cyan>\n";
 | 
			
		||||
            $output .= "<light_blue>{$this->helpMessage}</light_blue>\n";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!empty($this->syntaxMessage)) {
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
                    . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_blue>This command does everything you want to</light_blue>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
                    . "<light_gray><bold>Syntax:</bold></light_gray>\n"
 | 
			
		||||
                    . "    <light_green>mage example [light]</light_green>\n"
 | 
			
		||||
@ -74,6 +76,7 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                    . "        <green>mage example light</green>\n"
 | 
			
		||||
            ],
 | 
			
		||||
            'no_help_message' => [
 | 
			
		||||
                'name' => 'Example command',
 | 
			
		||||
                'helpMessage' => '',
 | 
			
		||||
                'examples' => [
 | 
			
		||||
                    [
 | 
			
		||||
@ -87,6 +90,7 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                ],
 | 
			
		||||
                'syntax' => 'mage example [light]',
 | 
			
		||||
                'output' => "\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_gray><bold>Syntax:</bold></light_gray>\n"
 | 
			
		||||
                    . "    <light_green>mage example [light]</light_green>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
@ -97,16 +101,19 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                    . "        <green>mage example light</green>\n"
 | 
			
		||||
            ],
 | 
			
		||||
            'no_examples' => [
 | 
			
		||||
                'name' => 'Example command',
 | 
			
		||||
                'helpMessage' => 'This command does everything you want to',
 | 
			
		||||
                'examples' => [],
 | 
			
		||||
                'syntax' => 'mage example [light]',
 | 
			
		||||
                'output' => "\n"
 | 
			
		||||
                    . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_blue>This command does everything you want to</light_blue>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
                    . "<light_gray><bold>Syntax:</bold></light_gray>\n"
 | 
			
		||||
                    . "    <light_green>mage example [light]</light_green>\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"
 | 
			
		||||
                    . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_blue>This command does everything you want to</light_blue>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
                    . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
 | 
			
		||||
                    . "    * Default command:\n"
 | 
			
		||||
@ -129,6 +137,7 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                    . "        <green>mage example light</green>\n"
 | 
			
		||||
            ],
 | 
			
		||||
            "stripping_colons" => [
 | 
			
		||||
                'name' => 'Example command',
 | 
			
		||||
                'helpMessage' => 'This command does everything you want to',
 | 
			
		||||
                'examples' => [
 | 
			
		||||
                    [
 | 
			
		||||
@ -142,7 +151,8 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                ],
 | 
			
		||||
                'syntax' => 'mage example [light]',
 | 
			
		||||
                'output' => "\n"
 | 
			
		||||
                    . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_blue>This command does everything you want to</light_blue>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
                    . "<light_gray><bold>Syntax:</bold></light_gray>\n"
 | 
			
		||||
                    . "    <light_green>mage example [light]</light_green>\n"
 | 
			
		||||
@ -154,13 +164,16 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                    . "        <green>mage example light</green>\n"
 | 
			
		||||
            ],
 | 
			
		||||
            "only_help" => [
 | 
			
		||||
                'name' => 'Example command',
 | 
			
		||||
                'helpMessage' => 'This command does everything you want to',
 | 
			
		||||
                'examples' => [],
 | 
			
		||||
                'syntax' => '',
 | 
			
		||||
                'output' => "\n"
 | 
			
		||||
                    . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_blue>This command does everything you want to</light_blue>\n"
 | 
			
		||||
            ],
 | 
			
		||||
            "only_examples" => [
 | 
			
		||||
                'name' => 'Example command',
 | 
			
		||||
                'helpMessage' => '',
 | 
			
		||||
                'examples' => [
 | 
			
		||||
                    [
 | 
			
		||||
@ -174,6 +187,7 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                ],
 | 
			
		||||
                'syntax' => '',
 | 
			
		||||
                'output' => "\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
 | 
			
		||||
                    . "    * Default command:\n"
 | 
			
		||||
                    . "        <green>mage example</green>\n"
 | 
			
		||||
@ -181,12 +195,40 @@ class AbstractCommandTest extends BaseTest
 | 
			
		||||
                    . "        <green>mage example light</green>\n"
 | 
			
		||||
            ],
 | 
			
		||||
            "only_syntax" => [
 | 
			
		||||
                'name' => 'Example command',
 | 
			
		||||
                'helpMessage' => '',
 | 
			
		||||
                'examples' => [],
 | 
			
		||||
                'syntax' => 'mage example [light]',
 | 
			
		||||
                'output' => "\n"
 | 
			
		||||
                    . "<cyan><bold>Command: </bold></cyan>Example command\n"
 | 
			
		||||
                    . "<light_gray><bold>Syntax:</bold></light_gray>\n"
 | 
			
		||||
                    . "    <light_green>mage example [light]</light_green>\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"
 | 
			
		||||
                    . "<light_blue>This command does everything you want to</light_blue>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
                    . "<light_gray><bold>Syntax:</bold></light_gray>\n"
 | 
			
		||||
                    . "    <light_green>mage example [light]</light_green>\n"
 | 
			
		||||
                    . "\n"
 | 
			
		||||
                    . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
 | 
			
		||||
                    . "    * Default command:\n"
 | 
			
		||||
                    . "        <green>mage example</green>\n"
 | 
			
		||||
                    . "    * Runs the command with lights:\n"
 | 
			
		||||
                    . "        <green>mage example light</green>\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']);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user