Fixes #12028: Add -h|--help option to console command to display help information

This commit is contained in:
Daniel Gomez Pan
2016-07-30 15:23:25 +02:00
committed by Alexander Makarov
parent f6ff90f672
commit cffb3832d1
2 changed files with 14 additions and 4 deletions

View File

@ -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'
];
}
/**