Skip to content

Commit

Permalink
Allowing plugin shells to be called without plugin notation
Browse files Browse the repository at this point in the history
Plugin shells will not require a plugin notation prefix anynmore
given that there are no shell name conflicts
  • Loading branch information
lorenzo committed Sep 13, 2014
1 parent 6f0347f commit e7357f9
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Console/ShellDispatcher.php
Expand Up @@ -20,6 +20,7 @@
use Cake\Core\Exception\Exception;
use Cake\Core\Plugin;
use Cake\Utility\Inflector;
use Cake\Shell\Task\CommandTask;

/**
* Shell dispatcher handles dispatching cli commands.
Expand Down Expand Up @@ -185,15 +186,33 @@ protected function _dispatch() {
* For all loaded plugins, add a short alias
*
* This permits a plugin which implements a shell of the same name to be accessed
* Using the plugin name alone
* Using the shell name alone
*
* @return void
*/
public function addShortPluginAliases() {
$plugins = Plugin::loaded();

$task = new CommandTask();
$list = $task->getShellList();
$fixed = array_flip($list['app']) + array_flip($list['CORE']);
$aliases = [];

foreach ($plugins as $plugin) {
self::alias($plugin, "$plugin.$plugin");
if (!isset($list[$plugin])) {
continue;
}

foreach ($list[$plugin] as $shell) {
$aliases += [$shell => $plugin];
}
}

foreach ($aliases as $shell => $plugin) {
if (isset($fixed[$shell])) {
continue;
}
static::alias($shell, "$plugin.$shell");
}
}

Expand Down

3 comments on commit e7357f9

@jadb
Copy link
Contributor

@jadb jadb commented on e7357f9 Sep 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When one does not have app-specific shells, it breaks with undefined 'app' key error (because CommandTask::getShellList() returns a filtered array).

@lorenzo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jadb would you be able to send a fix for this?

@jadb
Copy link
Contributor

@jadb jadb commented on e7357f9 Sep 21, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see #4683

Please sign in to comment.