From 488ba9ef853afc09b048a6990a9568ff62a780b7 Mon Sep 17 00:00:00 2001 From: AD7six Date: Thu, 7 Jun 2012 08:43:05 +0200 Subject: [PATCH] Make baking a plugin more user friendly. Changed the text when the plugin already exists to indicate that the task stops intentionally. If there are folder errors - report them in the cli. Choose the last plugin path by default Modify the app's bootstrap file if it's not being (obviously) loaded already. This means it is now possible to do: Console/cake bake plugin MyPlugin Console/cake bake model MyPlugin.MyModel Previously the above would result in an error (which only if you know), you'd fix by editing your Config/bootstrap.php file by hand before retrying to bake your model. --- lib/Cake/Console/Command/Task/PluginTask.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/PluginTask.php b/lib/Cake/Console/Command/Task/PluginTask.php index a10e072ce0d..0368240ee38 100644 --- a/lib/Cake/Console/Command/Task/PluginTask.php +++ b/lib/Cake/Console/Command/Task/PluginTask.php @@ -53,8 +53,9 @@ public function execute() { $plugin = Inflector::camelize($this->args[0]); $pluginPath = $this->_pluginPath($plugin); if (is_dir($pluginPath)) { - $this->out(__d('cake_console', 'Plugin: %s', $plugin)); + $this->out(__d('cake_console', 'Plugin: %s already exists, no action taken', $plugin)); $this->out(__d('cake_console', 'Path: %s', $pluginPath)); + return false; } else { $this->_interactive($plugin); } @@ -127,6 +128,9 @@ public function bake($plugin) { $errors = $Folder->errors(); if (!empty($errors)) { + foreach ($errors as $message) { + $this->error($message); + } return false; } @@ -144,8 +148,17 @@ public function bake($plugin) { $out .= "}\n\n"; $this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out); + $bootstrap = new File(APP . 'Config' . DS . 'bootstrap.php', false); + $contents = $bootstrap->read(); + if (!preg_match("@\n\s*CakePlugin::loadAll@", $contents)) { + $bootstrap->append("CakePlugin::load('$plugin', array('bootstrap' => false, 'routes' => false));"); + $this->out('', 1, Shell::VERBOSE); + $this->out(__d('cake_dev', '%s modified', APP . 'Config' . DS . 'bootstrap.php', 1, Shell::VERBOSE)); + } + $this->hr(); $this->out(__d('cake_console', 'Created: %s in %s', $plugin, $this->path . $plugin), 2); + } return true; @@ -170,7 +183,7 @@ public function findPath($pathOptions) { $this->out($i + 1 . '. ' . $option); } $prompt = __d('cake_console', 'Choose a plugin path from the paths above.'); - $choice = $this->in($prompt); + $choice = $this->in($prompt, null, 1); if (intval($choice) > 0 && intval($choice) <= $max) { $valid = true; }