Skip to content
Permalink
Browse files

Improve the Command Task reflection ability

To be more in sync with real live usage of the autocompletion through the CompletionShell, the plugin dot notation is only mandatory if there are multiple shells with the same name.

If plugins implement a Shell which has a unique name accross the core, the app and other plugins, the shell can be used without the dot notation. The CompletionShell should reflect that.
  • Loading branch information...
HavokInspiration committed Dec 2, 2015
1 parent a154b01 commit e7639ffd49ec84e3bb3882296ac88d801d697704
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/Shell/Task/CommandTask.php
@@ -19,6 +19,7 @@
use Cake\Core\App;
use Cake\Core\Plugin;
use Cake\Filesystem\Folder;
use Cake\Utility\Hash;
use Cake\Utility\Inflector;
use ReflectionClass;
use ReflectionMethod;
@@ -109,11 +110,14 @@ protected function _scanDir($dir)
public function commands()
{
$shellList = $this->getShellList();
$flatten = Hash::flatten($shellList);
$duplicates = array_intersect($flatten, array_unique(array_diff_key($flatten, array_unique($flatten))));
$duplicates = Hash::expand($duplicates);
$options = [];
foreach ($shellList as $type => $commands) {
$prefix = '';
if (!in_array(strtolower($type), ['app', 'core'])) {
if (!in_array(strtolower($type), ['app', 'core']) && isset($duplicates[$type])) {
$prefix = $type . '.';
}
@@ -143,7 +147,7 @@ public function subCommands($commandName)
$return = array_keys($taskMap);
$return = array_map('Cake\Utility\Inflector::underscore', $return);
$shellMethodNames = ['main', 'help', 'getOptionParser'];
$shellMethodNames = ['main', 'help', 'getOptionParser', 'initialize', 'runCommand'];
$baseClasses = ['Object', 'Shell', 'AppShell'];
@@ -182,6 +186,16 @@ public function getShell($commandName)
return false;
}
if (empty($pluginDot)) {
$shellList = $this->getShellList();
unset($shellList['CORE'], $shellList['app']);
foreach ($shellList as $plugin => $commands) {
if (in_array($commandName, $commands)) {
$pluginDot = $plugin . '.';
}
}
}
$name = Inflector::camelize($name);
$pluginDot = Inflector::camelize($pluginDot);
$class = App::className($pluginDot . $name, 'Shell', 'Shell');

0 comments on commit e7639ff

Please sign in to comment.
You can’t perform that action at this time.