Browse Source

Add console colours to command info output

1.0
Jakub Turek 10 years ago
parent
commit
94d301f66f
  1. 11
      Mage/Command/AbstractCommand.php
  2. 60
      tests/MageTest/Command/AbstractCommandTest.php

11
Mage/Command/AbstractCommand.php

@ -86,20 +86,19 @@ abstract class AbstractCommand
if (!empty($this->helpMessage)) { if (!empty($this->helpMessage)) {
$output .= "\n"; $output .= "\n";
$output .= $this->helpMessage . "\n"; $output .= "<cyan><bold>{$this->helpMessage}</bold></cyan>\n";
} }
if (!empty($this->syntaxMessage)) { if (!empty($this->syntaxMessage)) {
$output .= "\n"; $output .= "\n";
$output .= "Syntax:\n"; $output .= "<light_gray><bold>Syntax:</bold></light_gray>\n";
$output .= $indent; $output .= "$indent<light_green>{$this->syntaxMessage}</light_green>";
$output .= $this->syntaxMessage;
$output .= "\n"; $output .= "\n";
} }
if (!empty($this->usageExamples)) { if (!empty($this->usageExamples)) {
$output .= "\n"; $output .= "\n";
$output .= "Usage examples:\n"; $output .= "<light_gray><bold>Usage examples:</bold></light_gray>\n";
foreach ($this->usageExamples as $example) { foreach ($this->usageExamples as $example) {
$snippet = $example[0]; $snippet = $example[0];
$description = $example[1]; $description = $example[1];
@ -110,7 +109,7 @@ abstract class AbstractCommand
$output .= "\n$indent$indent"; $output .= "\n$indent$indent";
} }
$output .= $snippet; $output .= "<green>$snippet</green>";
$output .= "\n"; $output .= "\n";
} }
} }

60
tests/MageTest/Command/AbstractCommandTest.php

@ -62,16 +62,16 @@ class AbstractCommandTest extends BaseTest
], ],
'syntax' => 'mage example [light]', 'syntax' => 'mage example [light]',
'output' => "\n" 'output' => "\n"
. "This command does everything you want to\n" . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
. "\n" . "\n"
. "Syntax:\n" . "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " mage example [light]\n" . " <light_green>mage example [light]</light_green>\n"
. "\n" . "\n"
. "Usage examples:\n" . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
. " * Default command:\n" . " * Default command:\n"
. " mage example\n" . " <green>mage example</green>\n"
. " * Runs the command with lights:\n" . " * Runs the command with lights:\n"
. " mage example light\n" . " <green>mage example light</green>\n"
], ],
'no_help_message' => [ 'no_help_message' => [
'helpMessage' => '', 'helpMessage' => '',
@ -87,24 +87,24 @@ class AbstractCommandTest extends BaseTest
], ],
'syntax' => 'mage example [light]', 'syntax' => 'mage example [light]',
'output' => "\n" 'output' => "\n"
. "Syntax:\n" . "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " mage example [light]\n" . " <light_green>mage example [light]</light_green>\n"
. "\n" . "\n"
. "Usage examples:\n" . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
. " * Default command:\n" . " * Default command:\n"
. " mage example\n" . " <green>mage example</green>\n"
. " * Runs the command with lights:\n" . " * Runs the command with lights:\n"
. " mage example light\n" . " <green>mage example light</green>\n"
], ],
'no_examples' => [ 'no_examples' => [
'helpMessage' => 'This command does everything you want to', 'helpMessage' => 'This command does everything you want to',
'examples' => [], 'examples' => [],
'syntax' => 'mage example [light]', 'syntax' => 'mage example [light]',
'output' => "\n" 'output' => "\n"
. "This command does everything you want to\n" . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
. "\n" . "\n"
. "Syntax:\n" . "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " mage example [light]\n" . " <light_green>mage example [light]</light_green>\n"
], ],
"no_syntax" => [ "no_syntax" => [
'helpMessage' => 'This command does everything you want to', 'helpMessage' => 'This command does everything you want to',
@ -120,13 +120,13 @@ class AbstractCommandTest extends BaseTest
], ],
'syntax' => '', 'syntax' => '',
'output' => "\n" 'output' => "\n"
. "This command does everything you want to\n" . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
. "\n" . "\n"
. "Usage examples:\n" . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
. " * Default command:\n" . " * Default command:\n"
. " mage example\n" . " <green>mage example</green>\n"
. " * Runs the command with lights:\n" . " * Runs the command with lights:\n"
. " mage example light\n" . " <green>mage example light</green>\n"
], ],
"stripping_colons" => [ "stripping_colons" => [
'helpMessage' => 'This command does everything you want to', 'helpMessage' => 'This command does everything you want to',
@ -142,23 +142,23 @@ class AbstractCommandTest extends BaseTest
], ],
'syntax' => 'mage example [light]', 'syntax' => 'mage example [light]',
'output' => "\n" 'output' => "\n"
. "This command does everything you want to\n" . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
. "\n" . "\n"
. "Syntax:\n" . "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " mage example [light]\n" . " <light_green>mage example [light]</light_green>\n"
. "\n" . "\n"
. "Usage examples:\n" . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
. " * Default command:\n" . " * Default command:\n"
. " mage example\n" . " <green>mage example</green>\n"
. " * Runs the command with lights:\n" . " * Runs the command with lights:\n"
. " mage example light\n" . " <green>mage example light</green>\n"
], ],
"only_help" => [ "only_help" => [
'helpMessage' => 'This command does everything you want to', 'helpMessage' => 'This command does everything you want to',
'examples' => [], 'examples' => [],
'syntax' => '', 'syntax' => '',
'output' => "\n" 'output' => "\n"
. "This command does everything you want to\n" . "<cyan><bold>This command does everything you want to</bold></cyan>\n"
], ],
"only_examples" => [ "only_examples" => [
'helpMessage' => '', 'helpMessage' => '',
@ -174,19 +174,19 @@ class AbstractCommandTest extends BaseTest
], ],
'syntax' => '', 'syntax' => '',
'output' => "\n" 'output' => "\n"
. "Usage examples:\n" . "<light_gray><bold>Usage examples:</bold></light_gray>\n"
. " * Default command:\n" . " * Default command:\n"
. " mage example\n" . " <green>mage example</green>\n"
. " * Runs the command with lights:\n" . " * Runs the command with lights:\n"
. " mage example light\n" . " <green>mage example light</green>\n"
], ],
"only_syntax" => [ "only_syntax" => [
'helpMessage' => '', 'helpMessage' => '',
'examples' => [], 'examples' => [],
'syntax' => 'mage example [light]', 'syntax' => 'mage example [light]',
'output' => "\n" 'output' => "\n"
. "Syntax:\n" . "<light_gray><bold>Syntax:</bold></light_gray>\n"
. " mage example [light]\n" . " <light_green>mage example [light]</light_green>\n"
] ]
]; ];
} }

Loading…
Cancel
Save