From cffb3832d19d7101e99a1cf30ec22caa17aadf30 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Pan Date: Sat, 30 Jul 2016 15:23:25 +0200 Subject: [PATCH] Fixes #12028: Add -h|--help option to console command to display help information --- framework/CHANGELOG.md | 2 +- framework/console/Controller.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 79405ced86..796991eedc 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -21,7 +21,7 @@ Yii Framework 2 Change Log - Enh #12038: Introduced `yii\base\ViewNotFoundException` which is thrown when views file doesn't exists, used it in `ViewAction` (samdark) - Enh #11979: Added `yii\mutex\OracleMutex` which implements mutex "lock" mechanism via Oracle locks (zlakomanoff) - Enh #12082: Used `jQuery.on(` instead of event method to ensure forwards compatibility (newerton) - +- Enh #12028: Add -h|--help option to console command to display help information (pana1990) 2.0.9 July 11, 2016 ------------------- diff --git a/framework/console/Controller.php b/framework/console/Controller.php index d8d6807d29..3080e2ba83 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -51,7 +51,11 @@ class Controller extends \yii\base\Controller * If not set, ANSI color will only be enabled for terminals that support it. */ public $color; - + /** + * @var boolean whether to display help information about current command. + * @since 2.0.10 + */ + public $help; /** * @var array the options passed during execution. */ @@ -116,6 +120,10 @@ class Controller extends \yii\base\Controller } } } + if ($this->help) { + $route = $this->id . '/' . $id; + return Yii::$app->runAction('help', [$route]); + } return parent::runAction($id, $params); } @@ -303,7 +311,7 @@ class Controller extends \yii\base\Controller public function options($actionID) { // $actionId might be used in subclasses to provide options specific to action id - return ['color', 'interactive']; + return ['color', 'interactive', 'help']; } /** @@ -318,7 +326,9 @@ class Controller extends \yii\base\Controller */ public function optionAliases() { - return []; + return [ + 'h' => 'help' + ]; } /**