mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 14:28:27 +08:00
Added bash completion file for ./yii commands
This allows to auto-complete commands available by the `./yii` executable on the bash by expanding the first argument with the TAB key. E.g. Typing `./yii [TAB]` will list all commands. `./yii mig[TAB]` will auto-complete to `./yii migrate` and tab after that will list all migration sub-commands(actions). fixes #475
This commit is contained in:
@ -68,6 +68,32 @@ class HelpController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all available controllers and actions in machine readable format.
|
||||
* This is used for bash completion.
|
||||
* @since 2.0.11
|
||||
*/
|
||||
public function actionList()
|
||||
{
|
||||
$commands = $this->getCommandDescriptions();
|
||||
foreach ($commands as $command => $description) {
|
||||
$result = Yii::$app->createController($command);
|
||||
if ($result === false || !($result[0] instanceof Controller)) {
|
||||
continue;
|
||||
}
|
||||
/** @var $controller Controller */
|
||||
list($controller, $actionID) = $result;
|
||||
$actions = $this->getActions($controller);
|
||||
if (!empty($actions)) {
|
||||
$prefix = $controller->getUniqueId();
|
||||
$this->stdout("$prefix\n");
|
||||
foreach ($actions as $action) {
|
||||
$this->stdout("$prefix/$action\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available command names.
|
||||
* @return array all available command names
|
||||
|
Reference in New Issue
Block a user