|
|
@@ -211,7 +211,7 @@ class Shell
|
|
|
*/
|
|
|
public function startup()
|
|
|
{
|
|
|
- if (!(bool)$this->param('requested')) {
|
|
|
+ if (!$this->param('requested')) {
|
|
|
$this->_welcome();
|
|
|
}
|
|
|
}
|
|
|
@@ -300,22 +300,29 @@ class Shell
|
|
|
*
|
|
|
* `return $this->dispatchShell('schema', 'create', 'i18n', '--dry');`
|
|
|
*
|
|
|
+ * With an array having two key / value pairs:
|
|
|
+ * - `command` can accept either a string or an array. Represents the command to dispatch
|
|
|
+ * - `extra` can accept an array of extra parameters to pass on to the dispatcher. This
|
|
|
+ * parameters will be available in the `param` property of the called `Shell`
|
|
|
+ *
|
|
|
+ * `return $this->dispatchShell([
|
|
|
+ * 'command' => 'schema create DbAcl',
|
|
|
+ * 'extra' => ['param' => 'value']
|
|
|
+ * ]);`
|
|
|
+ *
|
|
|
+ * or
|
|
|
+ *
|
|
|
+ * `return $this->dispatchShell([
|
|
|
+ * 'command' => ['schema', 'create', 'DbAcl'],
|
|
|
+ * 'extra' => ['param' => 'value']
|
|
|
+ * ]);`
|
|
|
+ *
|
|
|
* @return mixed The return of the other shell.
|
|
|
* @link http://book.cakephp.org/3.0/en/console-and-shells.html#invoking-other-shells-from-your-shell
|
|
|
*/
|
|
|
public function dispatchShell()
|
|
|
{
|
|
|
- $args = func_get_args();
|
|
|
- $extra = [];
|
|
|
- if (is_array($args[0]) && isset($args[0]['command'])) {
|
|
|
- if (!empty($args[0]['extra'])) {
|
|
|
- $extra = $args[0]['extra'];
|
|
|
- }
|
|
|
-
|
|
|
- $args = explode(' ', $args[0]['command']);
|
|
|
- } elseif (is_string($args[0]) && count($args) === 1) {
|
|
|
- $args = explode(' ', $args[0]);
|
|
|
- }
|
|
|
+ list($args, $extra) = $this->parseDispatchArguments(func_get_args());
|
|
|
|
|
|
if (!isset($extra['requested'])) {
|
|
|
$extra['requested'] = true;
|
|
|
@@ -326,6 +333,39 @@ class Shell
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Parses the arguments for the dispatchShell() method.
|
|
|
+ *
|
|
|
+ * @param array $args Arguments fetch from the dispatchShell() method with
|
|
|
+ * func_get_args()
|
|
|
+ * @return array First value has to be an array of the command arguments.
|
|
|
+ * Second value has to be an array of extra parameter to pass on to the dispatcher
|
|
|
+ */
|
|
|
+ public function parseDispatchArguments($args)
|
|
|
+ {
|
|
|
+ $extra = [];
|
|
|
+
|
|
|
+ if (is_string($args[0]) && count($args) === 1) {
|
|
|
+ $args = explode(' ', $args[0]);
|
|
|
+ return [$args, $extra];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_array($args[0]) && !empty($args[0]['command'])) {
|
|
|
+ $command = $args[0]['command'];
|
|
|
+ if (is_string($command)) {
|
|
|
+ $command = explode(' ', $command);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($args[0]['extra'])) {
|
|
|
+ $extra = $args[0]['extra'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [$command, $extra];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [$args, $extra];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Runs the Shell with the provided argv.
|
|
|
*
|
|
|
* Delegates calls to Tasks and resolves methods inside the class. Commands are looked
|