浏览代码

CLI error() should return early

euromark 12 年之前
父节点
当前提交
66c6a2f08a

+ 2 - 2
Console/Command/ConvertShell.php

@@ -52,14 +52,14 @@ class ConvertShell extends AppShell {
 		$folder = APP;
 		$mode = $this->params['mode'];
 		if (empty($mode) || !in_array($mode, $this->modes)) {
-			$this->error('Invalid mode', 'Please specify d2u, u2d, git (d2u+u2d) ...');
+			return $this->error('Invalid mode', 'Please specify d2u, u2d, git (d2u+u2d) ...');
 		}
 		if (!empty($this->args)) {
 			$folder = array_shift($this->args);
 			$folder = realpath($folder);
 		}
 		if (empty($folder)) {
-			$this->error('Invalid dir', 'No valid dir given (either absolute or relative to APP)');
+			return $this->error('Invalid dir', 'No valid dir given (either absolute or relative to APP)');
 		}
 
 		$this->_convert($folder, $mode);

+ 7 - 7
Console/Command/CopyShell.php

@@ -157,7 +157,7 @@ class CopyShell extends AppShell {
 		$this->out('');
 
 		if (empty($connection) || $connection === 'q') {
-			$this->error('Aborted!');
+			return $this->error('Aborted!');
 		} elseif ($connection === 'h') {
 			$this->help();
 			return;
@@ -170,17 +170,17 @@ class CopyShell extends AppShell {
 			if (!empty($configName[1])) {
 				$this->configName = $configName[1];
 			} else {
-				$this->error('Invalid config name \''.$configs[$connection-1].'\'');
+				return $this->error('Invalid config name \''.$configs[$connection-1].'\'');
 			}
 		}
 
 		# allow c, v and p only with app configs -> set params (by splitting app_configName into app and configName)
 		if ($this->type > 3 || $this->type > 0 && $configName[0] !== 'app') {
-			$this->error('"-c" (-cake), "-v" (-vendor) and "-p" (-plugin) only possible with app configs (not with custom ones)');
+			return $this->error('"-c" (-cake), "-v" (-vendor) and "-p" (-plugin) only possible with app configs (not with custom ones)');
 		}
 
 		if (empty($configuration)) {
-			$this->error('Error...');
+			return $this->error('Error...');
 		} else {
 			$this->out('... Config \''.$this->types[$this->type].'_'.$this->configName.'\' selected ...');
 		}
@@ -290,7 +290,7 @@ class CopyShell extends AppShell {
 			}
 
 			if ($action === 'q') {
-				$this->error('Aborted!');
+				return $this->error('Aborted!');
 			}
 			if (in_array($action, $allowedActions)) {
 				# synch can destroy local information that might not have been saved yet, so confirm
@@ -509,7 +509,7 @@ class CopyShell extends AppShell {
 		$File = new File($this->localFolder.'config'.DS.$this->configCustomFile);
 
 		if (!$File->exists()) {
-			$this->error('No config file present (/config/'.$this->configCustomFile.')!');
+			return $this->error('No config file present (/config/'.$this->configCustomFile.')!');
 		}
 		$File->open('r');
 
@@ -547,7 +547,7 @@ class CopyShell extends AppShell {
 				$config = trim(str_replace('site ','', $c));
 				if (!empty($config)) {
 					if (!$this->isValidConfigName($config)) {
-						$this->error('Invalid Config Name \''.$config.'\' in /config/'.$this->configCustomFile.'!'.NL.'Allowed: [app|custom]+\'_\'+{a-z0-9-} or [cake|vendor|plugin]');
+						return $this->error('Invalid Config Name \''.$config.'\' in /config/'.$this->configCustomFile.'!'.NL.'Allowed: [app|custom]+\'_\'+{a-z0-9-} or [cake|vendor|plugin]');
 					}
 
 					if ($this->typeMatchesConfigName($config, $this->type)) {

+ 1 - 1
Console/Command/EncodingShell.php

@@ -39,7 +39,7 @@ class EncodingShell extends AppShell {
 			$folder = realpath($folder);
 		}
 		if (empty($folder)) {
-			$this->error('Invalid dir', 'No valid dir given (either absolute or relative to APP)');
+			return $this->error('Invalid dir', 'No valid dir given (either absolute or relative to APP)');
 		}
 		$this->out('Searching folder:');
 		$this->out($folder, 2);

+ 2 - 2
Console/Command/FolderSyncShell.php

@@ -60,10 +60,10 @@ class FolderSyncShell extends AppShell {
 			$this->targetFolder = realpath($this->params['target']);
 		}
 		if (!$this->sourceFolder || !is_dir($this->sourceFolder)) {
-			$this->error('Folder not exists', 'Please specify a valid source folder');
+			return $this->error('Folder not exists', 'Please specify a valid source folder');
 		}
 		if (!$this->targetFolder || !is_dir($this->targetFolder)) {
-			$this->error('Folder not exists', 'Please specify a valid target folder');
+			return $this->error('Folder not exists', 'Please specify a valid target folder');
 		}
 
 		if (!empty($this->params['invert'])) {

+ 1 - 1
Console/Command/HashShell.php

@@ -31,7 +31,7 @@ class HashShell extends AppShell {
 		while (!isset($type) || !in_array($type-1, $types)) {
 			$type = $this->in(__('Select hashType - or [q] to quit'), null, self::DEFAULT_HASH_ALG);
 			if ($type === 'q') {
-				$this->error('Aborted!');
+				return $this->error('Aborted!');
 			}
 		}
 		$type--;

+ 3 - 3
Console/Command/IndentShell.php

@@ -75,7 +75,7 @@ class IndentShell extends AppShell {
 
 				$folder = realpath($folder);
 				if (!file_exists($folder)) {
-					$this->error('folder not exists: ' . $folder . '');
+					return $this->error('folder not exists: ' . $folder . '');
 				}
 				$this->_paths[] = $folder;
 			} elseif ($this->args[0] === 'app') {
@@ -96,7 +96,7 @@ class IndentShell extends AppShell {
 			} else {
 				$continue = $this->in(__('Modifying files! Continue?'), array('y', 'n'), 'n');
 				if (strtolower($continue) !== 'y' && strtolower($continue) !== 'yes') {
-					$this->error('...aborted');
+					return $this->error('...aborted');
 				}
 
 				$this->_correctFiles();
@@ -253,7 +253,7 @@ class IndentShell extends AppShell {
 						$pos++;
 						$spaces += $this->settings['spacesPerTab'];
 					} else {
-						$this->error('???');
+						return $this->error('???');
 					}
 
 					$newPiece = mb_substr($newPiece, 1);

+ 1 - 1
Console/Command/PhpTagShell.php

@@ -85,7 +85,7 @@ class PhpTagShell extends AppShell {
 				}
 
 				if ($action === 'q') {
-					$this->error('Abort... Done');
+					return $this->error('Abort... Done');
 				} elseif ($action === 'y') {
 					$res = $c;
 					if (in_array('leading', $error)) {

+ 1 - 1
Console/Command/PwdShell.php

@@ -31,7 +31,7 @@ class PwdShell extends AppShell {
 			}
 		}
 		if (!$class || !method_exists($class, 'password')) {
-			$this->error(__('No Auth Component found'));
+			return $this->error(__('No Auth Component found'));
 		}
 
 		$this->out('Using: '.$class);

+ 3 - 3
Console/Command/ResetShell.php

@@ -38,7 +38,7 @@ class ResetShell extends AppShell {
 
 		$this->User = ClassRegistry::init(CLASS_USER);
 		if (!$this->User->hasField('email')) {
-			$this->error(CLASS_USER.' model doesnt have an email field!');
+			return $this->error(CLASS_USER.' model doesnt have an email field!');
 		}
 
 		$this->hr();
@@ -65,7 +65,7 @@ class ResetShell extends AppShell {
 			}
 		}
 		if (!is_object($this->Auth)) {
-			$this->error('No Auth Component found');
+			return $this->error('No Auth Component found');
 		}
 
 		$this->out('Using: '.get_class($this->Auth).' (Abort with STRG+C)');
@@ -90,7 +90,7 @@ class ResetShell extends AppShell {
 
 		$this->User = ClassRegistry::init(CLASS_USER);
 		if (!$this->User->hasField('password')) {
-			$this->error(CLASS_USER.' model doesnt have a password field!');
+			return $this->error(CLASS_USER.' model doesnt have a password field!');
 		}
 
 		if (method_exists($this->User, 'escapeValue')) {

+ 2 - 2
Console/Command/UserShell.php

@@ -111,7 +111,7 @@ class UserShell extends AppShell {
 		$this->out('');
 		$continue = $this->in(__('Continue? '), array('y', 'n'), 'n');
 		if ($continue !== 'y') {
-			$this->error('Not Executed!');
+			return $this->error('Not Executed!');
 		}
 
 		$this->out('');
@@ -119,7 +119,7 @@ class UserShell extends AppShell {
 		if ($this->User->save($data)) {
 			$this->out('User inserted! ID: '.$this->User->id);
 		} else {
-			$this->error('User could not be inserted ('.print_r($this->User->validationErrors, true).')');
+			return $this->error('User could not be inserted ('.print_r($this->User->validationErrors, true).')');
 		}
 	}
 

+ 3 - 3
Console/Command/WhitespaceShell.php

@@ -30,7 +30,7 @@ class WhitespaceShell extends AppShell {
 
 		$action = $this->in(__('Continue? [y]/[n]'), array('y', 'n'), 'n');
 		if ($action === 'n') {
-			$this->error('Aborted');
+			return $this->error('Aborted');
 		}
 
 		$folders = array();
@@ -80,7 +80,7 @@ class WhitespaceShell extends AppShell {
 			}
 
 			if ($action === 'q') {
-				$this->error('Abort... Done');
+				return $this->error('Abort... Done');
 
 			} elseif ($action === 'y') {
 				if ($error === 'leading') {
@@ -119,7 +119,7 @@ class WhitespaceShell extends AppShell {
 
 		$action = $this->in(__('Continue? [y]/[n]'), array('y', 'n'), 'n');
 		if ($action === 'n') {
-			$this->error('Aborted');
+			return $this->error('Aborted');
 		}
 
 		foreach ($files as $file) {