Commit 740a7694 by Carsten Brandt

improved HelpController with messages for each command

parent 62378c3b
......@@ -12,7 +12,7 @@ use yii\console\Exception;
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:
* 1. Create a configuration file using 'template' action:
......
......@@ -13,7 +13,7 @@ use yii\console\Exception;
use yii\caching\Cache;
/**
* This command allows you to flush cache.
* Allows you to flush cache.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
......
......@@ -15,7 +15,7 @@ use yii\helpers\FileHelper;
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"
......
......@@ -16,7 +16,7 @@ use yii\helpers\Console;
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
* the application or the detailed instructions about using
......@@ -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.
* @param Controller $controller the controller instance
* @return array all available action IDs.
......@@ -141,11 +167,19 @@ class HelpController extends Controller
*/
protected function getHelp()
{
$commands = $this->getCommands();
$commands = $this->getCommandDescriptions();
if (!empty($commands)) {
$this->stdout("\nThe following commands are available:\n\n", Console::BOLD);
foreach ($commands as $command) {
echo "- " . $this->ansiFormat($command, Console::FG_YELLOW) . "\n";
$len = 0;
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();
$this->stdout("\nTo see the help of each command, enter:\n", Console::BOLD);
......
......@@ -14,7 +14,8 @@ use yii\console\Exception;
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`
* setting in config file:
*
......
......@@ -17,7 +17,7 @@ use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper;
/**
* This command manages application migrations.
* Manages application migrations.
*
* A migration means a set of persistent changes to the application environment
* 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