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:
Carsten Brandt
2016-11-09 22:30:33 +01:00
parent 612afdbc66
commit 05b17ebb65
4 changed files with 74 additions and 0 deletions

View File

@ -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