Commit 740a7694 by Carsten Brandt

improved HelpController with messages for each command

parent 62378c3b
...@@ -12,7 +12,7 @@ use yii\console\Exception; ...@@ -12,7 +12,7 @@ use yii\console\Exception;
use yii\console\Controller; use yii\console\Controller;
/** /**
* This command allows you to combine and compress your JavaScript and CSS files. * Allows you to combine and compress your JavaScript and CSS files.
* *
* Usage: * Usage:
* 1. Create a configuration file using 'template' action: * 1. Create a configuration file using 'template' action:
......
...@@ -13,7 +13,7 @@ use yii\console\Exception; ...@@ -13,7 +13,7 @@ use yii\console\Exception;
use yii\caching\Cache; use yii\caching\Cache;
/** /**
* This command allows you to flush cache. * Allows you to flush cache.
* *
* @author Alexander Makarov <sam@rmcreative.ru> * @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0 * @since 2.0
......
...@@ -15,7 +15,7 @@ use yii\helpers\FileHelper; ...@@ -15,7 +15,7 @@ use yii\helpers\FileHelper;
use yii\test\FixtureTrait; use yii\test\FixtureTrait;
/** /**
* This command manages loading and unloading fixtures. * Manages loading and unloading fixtures.
* *
* ~~~ * ~~~
* #load fixtures from UsersFixture class with default namespace "tests\unit\fixtures" * #load fixtures from UsersFixture class with default namespace "tests\unit\fixtures"
......
...@@ -16,7 +16,7 @@ use yii\helpers\Console; ...@@ -16,7 +16,7 @@ use yii\helpers\Console;
use yii\helpers\Inflector; use yii\helpers\Inflector;
/** /**
* This command provides help information about console commands. * Provides help information about console commands.
* *
* This command displays the available command list in * This command displays the available command list in
* the application or the detailed instructions about using * the application or the detailed instructions about using
...@@ -82,6 +82,32 @@ class HelpController extends Controller ...@@ -82,6 +82,32 @@ class HelpController extends Controller
} }
/** /**
* Returns an array of commands an their descriptions.
* @return array all available commands as keys and their description as values.
*/
protected function getCommandDescriptions()
{
$descriptions = [];
foreach ($this->getCommands() as $command) {
$description = '';
$result = Yii::$app->createController($command);
if ($result !== false) {
list($controller, $actionID) = $result;
$class = new \ReflectionClass($controller);
$docLines = preg_split('~(\n|\r|\r\n)~', $class->getDocComment());
if (isset($docLines[1])) {
$description = trim($docLines[1], ' *');
}
}
$descriptions[$command] = $description;
}
return $descriptions;
}
/**
* Returns all available actions of the specified controller. * Returns all available actions of the specified controller.
* @param Controller $controller the controller instance * @param Controller $controller the controller instance
* @return array all available action IDs. * @return array all available action IDs.
...@@ -141,11 +167,19 @@ class HelpController extends Controller ...@@ -141,11 +167,19 @@ class HelpController extends Controller
*/ */
protected function getHelp() protected function getHelp()
{ {
$commands = $this->getCommands(); $commands = $this->getCommandDescriptions();
if (!empty($commands)) { if (!empty($commands)) {
$this->stdout("\nThe following commands are available:\n\n", Console::BOLD); $this->stdout("\nThe following commands are available:\n\n", Console::BOLD);
foreach ($commands as $command) { $len = 0;
echo "- " . $this->ansiFormat($command, Console::FG_YELLOW) . "\n"; foreach ($commands as $command => $description) {
if (($l = strlen($command)) > $len) {
$len = $l;
}
}
foreach ($commands as $command => $description) {
echo "- " . $this->ansiFormat($command, Console::FG_YELLOW);
echo str_repeat(' ', $len + 3 - strlen($command)) . $description;
echo "\n";
} }
$scriptName = $this->getScriptName(); $scriptName = $this->getScriptName();
$this->stdout("\nTo see the help of each command, enter:\n", Console::BOLD); $this->stdout("\nTo see the help of each command, enter:\n", Console::BOLD);
......
...@@ -14,7 +14,8 @@ use yii\console\Exception; ...@@ -14,7 +14,8 @@ use yii\console\Exception;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
/** /**
* This command extracts messages to be translated from source files. * Extracts messages to be translated from source files.
*
* The extracted messages can be saved the following depending on `format` * The extracted messages can be saved the following depending on `format`
* setting in config file: * setting in config file:
* *
......
...@@ -17,7 +17,7 @@ use yii\helpers\ArrayHelper; ...@@ -17,7 +17,7 @@ use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
/** /**
* This command manages application migrations. * Manages application migrations.
* *
* A migration means a set of persistent changes to the application environment * A migration means a set of persistent changes to the application environment
* that is shared among different developers. For example, in an application * that is shared among different developers. For example, in an application
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment