Skip to content
This repository
Browse code

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.
  • Loading branch information...
commit 488ba9ef853afc09b048a6990a9568ff62a780b7 1 parent f3464b0
Andy Dawson authored June 07, 2012
17  lib/Cake/Console/Command/Task/PluginTask.php
@@ -53,8 +53,9 @@ public function execute() {
53 53
 			$plugin = Inflector::camelize($this->args[0]);
54 54
 			$pluginPath = $this->_pluginPath($plugin);
55 55
 			if (is_dir($pluginPath)) {
56  
-				$this->out(__d('cake_console', 'Plugin: %s', $plugin));
  56
+				$this->out(__d('cake_console', 'Plugin: %s already exists, no action taken', $plugin));
57 57
 				$this->out(__d('cake_console', 'Path: %s', $pluginPath));
  58
+				return false;
58 59
 			} else {
59 60
 				$this->_interactive($plugin);
60 61
 			}
@@ -127,6 +128,9 @@ public function bake($plugin) {
127 128
 
128 129
 			$errors = $Folder->errors();
129 130
 			if (!empty($errors)) {
  131
+				foreach ($errors as $message) {
  132
+					$this->error($message);
  133
+				}
130 134
 				return false;
131 135
 			}
132 136
 
@@ -144,8 +148,17 @@ public function bake($plugin) {
144 148
 			$out .= "}\n\n";
145 149
 			$this->createFile($this->path . $plugin . DS . 'Model' . DS . $modelFileName, $out);
146 150
 
  151
+			$bootstrap = new File(APP . 'Config' . DS . 'bootstrap.php', false);
  152
+			$contents = $bootstrap->read();
  153
+			if (!preg_match("@\n\s*CakePlugin::loadAll@", $contents)) {
  154
+				$bootstrap->append("CakePlugin::load('$plugin', array('bootstrap' => false, 'routes' => false));");
  155
+				$this->out('', 1, Shell::VERBOSE);
  156
+				$this->out(__d('cake_dev', '%s modified', APP . 'Config' . DS . 'bootstrap.php', 1, Shell::VERBOSE));
  157
+			}
  158
+
147 159
 			$this->hr();
148 160
 			$this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
  161
+
149 162
 		}
150 163
 
151 164
 		return true;
@@ -170,7 +183,7 @@ public function findPath($pathOptions) {
170 183
 				$this->out($i + 1 . '. ' . $option);
171 184
 			}
172 185
 			$prompt = __d('cake_console', 'Choose a plugin path from the paths above.');
173  
-			$choice = $this->in($prompt);
  186
+			$choice = $this->in($prompt, null, 1);
174 187
 			if (intval($choice) > 0 && intval($choice) <= $max) {
175 188
 				$valid = true;
176 189
 			}

0 notes on commit 488ba9e

Please sign in to comment.
Something went wrong with that request. Please try again.