incubator-kitty-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovar...@apache.org
Subject svn commit: r1299269 - in /incubator/kitty/trunk/src/main/groovy/org/apache/kitty: CmdShell.groovy CmdShellBuilder.groovy Main.groovy utils/Constants.groovy
Date Sat, 10 Mar 2012 20:43:12 GMT
Author: anovarini
Date: Sat Mar 10 20:43:12 2012
New Revision: 1299269

URL: http://svn.apache.org/viewvc?rev=1299269&view=rev
Log:
Started refactoring in order to work on kitty-5, removed static method definitions, sent some
output to reader instead of standard output

Added:
    incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy
Modified:
    incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy
    incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy
    incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Constants.groovy

Modified: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy?rev=1299269&r1=1299268&r2=1299269&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy (original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShell.groovy Sat Mar 10 20:43:12
2012
@@ -40,17 +40,18 @@ import org.apache.kitty.utils.Help
  */
 class CmdShell {
 
-	def static final PROMPT = "kitty> "
+	static final PROMPT = "kitty> "
 
 	static final String HOST = "localhost"
 
 	static final String PORT = "1099"
 
-	static Client client
+	Client client
+    ConsoleReader reader = new ConsoleReader()
 
-	def static remote
+	def remote
 
-	static commands = [
+	def commands = [
 		"help",
 		"connect",
 		"disconnect",
@@ -66,32 +67,22 @@ class CmdShell {
 		"setdomain"
 	]
 
-	/**
-	 *
-	 */
-	public CmdShell() {
-		// TODO Auto-generated constructor stub
-	}
-
-	static main(args) {
-		startShell()
-	}
-
-	static startShell() {
+    CmdShell(Client client) {
+        this.client = client
+    }
 
-		client = new Client()
+	void startShell() {
 
 		// TODO add Windows compatibility check
 		def historyFile = new File(System.getProperty("user.home"), "kitty.history")
 		historyFile.createNewFile()
 
 		def history = new History(historyFile)
-		def reader = new ConsoleReader()
 
-		reader.setBellEnabled(false)
-		reader.setUseHistory(true)
-		reader.setDefaultPrompt(PROMPT)
-		reader.setHistory(history)
+		reader.setBellEnabled false
+		reader.setUseHistory true
+        reader.setHistory history
+        reader.setDefaultPrompt PROMPT
 		reader.addCompletor(new SimpleCompletor(commands as String[]))
 
 		LOOP: while (true) {
@@ -112,7 +103,7 @@ class CmdShell {
 		}
 	}
 
-	static inputHandler(String input) {
+	void inputHandler(String input) {
 		Integer index = 0
 		String[] params
 
@@ -134,14 +125,14 @@ class CmdShell {
 					break;
 				case 1:
 					if (params.length > 5) {
-						println "You have entered an invalid number of parameters, you may enter host and port
as parameters only"
+						reader.printString "You have entered an invalid number of parameters, you may enter
host and port as parameters only"
 						break;
 					}
 					if (params.length == 5) {
 						cmdConnect(params[1], params[2], params[3], params[4])
 					}
 					else if (params.length == 4) {
-						println "Please supply a password"
+                        reader.printString "Please supply a password"
 					}
 					else if (params.length == 3) {
 						cmdConnect(params[1], params[2])
@@ -176,8 +167,8 @@ class CmdShell {
 						cmdCd(params[1])
 					}
 					else {
-						println Constants.ERROR_TOO_FEW_PARAMETERS
-						println "You must enter a path parameter after 'cd'"
+                        reader.printString Constants.ERROR_TOO_FEW_PARAMETERS
+                        reader.printString "You must enter a path parameter after 'cd'"
 					}
 					break;
 				case 8:
@@ -185,8 +176,8 @@ class CmdShell {
 						cmdGet(params[1])
 					}
 					else {
-						println Constants.ERROR_TOO_FEW_PARAMETERS
-						println "You must enter at 1 parameter after the command"
+                        reader.printString Constants.ERROR_TOO_FEW_PARAMETERS
+                        reader.printString "You must enter at 1 parameter after the command"
 					}
 					break;
 				case 9:
@@ -194,8 +185,8 @@ class CmdShell {
 						cmdSet(params[1], params[2])
 					}
 					else {
-						println Constants.ERROR_TOO_FEW_PARAMETERS
-						println "You must enter an attribute parameter and a value parameter"
+                        reader.printString Constants.ERROR_TOO_FEW_PARAMETERS
+                        reader.printString "You must enter an attribute parameter and a value
parameter"
 					}
 					break;
 				case 10:
@@ -203,8 +194,8 @@ class CmdShell {
 						cmdInvoke(params[1],params[2])
 					}
 					else {
-						println Constants.ERROR_TOO_FEW_PARAMETERS
-						println "You must enter an operation name followed by parameter(s)"
+                        reader.printString Constants.ERROR_TOO_FEW_PARAMETERS
+                        reader.printString "You must enter an operation name followed by
parameter(s)"
 					}
 
 					break;
@@ -216,8 +207,8 @@ class CmdShell {
 						cmdSetDomain(params[1])
 					}
 					else {
-						println Constants.ERROR_TOO_FEW_PARAMETERS
-						println "You must enter a domain name parameter after 'setdomain' command"
+                        reader.printString Constants.ERROR_TOO_FEW_PARAMETERS
+                        reader.printString "You must enter a domain name parameter after
'setdomain' command"
 					}
 					break;
 				default:
@@ -225,139 +216,139 @@ class CmdShell {
 			}
 		}
 		else {
-			println input + " is not a valid command"
+            reader.printString (input + " is not a valid command")
 		}
 	}
 
-	static cmdHelp() {
+	void cmdHelp() {
 		Help h = new Help()
-		println h.toString()
+        reader.printString h.toString()
 	}
 
-    static cmdConnect(String... args) {
+    void cmdConnect(String... args) {
 
         def host = args.length > 1 ? args[0] : HOST
         def port = args.length >= 2 ? args[1] : PORT
 
         if (args?.length == 4) {
-            getClient().connect(host, port, args[2], args[3])
+            client.connect(host, port, args[2], args[3])
         }
         else {
-            getClient().connect(host, port)
+            client.connect(host, port)
         }
-        this.remote = getClient().getRemote()
+        this.remote = client.remote
         if (this.remote) {
-            println "Successfully connected to host"
+            reader.printString "Successfully connected to host"
         }
         else {
-            println "Connection attempt was unsuccessful"
+            reader.printString "Connection attempt was unsuccessful"
         }
     }
 
-	static cmdDisconnect() {
-		println "disconnecting..."
-		if (client.getRemote()) {
+	void cmdDisconnect() {
+        reader.printString "disconnecting..."
+		if (client.remote) {
 			client.disconnect()
-			if (!client.getRemote()) {
-				println "successfully disconnected from host"
+			if (!client.remote) {
+                reader.printString "successfully disconnected from host"
 			}
 		}
 		else {
-			println "client can not disconnect because it is not connected to a host"
+            reader.printString "client can not disconnect because it is not connected to
a host"
 		}
 	}
 
-	static cmdExit() {
+	void cmdExit() {
         if (client.getRemote()) {
             client.disconnect()
             if (!client.getRemote()) {
-                println "successfully disconnected from host"
+                reader.printString "successfully disconnected from host"
             }
         }
-		println "exiting..."
-		println "successfully exited kitty"
+        reader.printString  "exiting..."
+        reader.printString  "successfully exited kitty"
 	}
 
-	static cmdLs() {
-		println "listing files and directories..."
+	void cmdLs() {
+        reader.printString  "listing files and directories..."
 		if (remote) {
 			getClient().ls()
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 
-	static cmdDomains() {
+	void cmdDomains() {
 		def domains = getClient().domains()
 		if (domains) {
-			println "Domains Detected: "
+            reader.printString  "Domains Detected: "
             domains.eachWithIndex() { obj, i -> println " ${i}: ${obj}" }
 
 		}
 		else {
-			println "No domains are available"
+            reader.printString  "No domains are available"
 		}
 	}
 
-	static cmdCd(String path) {
-		println "changing remote path..."
+	void cmdCd(String path) {
+        reader.printString  "changing remote path..."
 		if (remote) {
 			getClient().cd(path)
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 
-	static cmdGet(def attr) {
-		println "get $attr..."
+	void cmdGet(def attr) {
+        reader.printString  "get $attr..."
 		if (remote) {
 			getClient().get(attr)
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 
-	static cmdSet(def attr, def val) {
-		println "set $attr to $val"
+	void cmdSet(def attr, def val) {
+        reader.printString  "set $attr to $val"
 		if (remote) {
 			getClient().set(attr, val)
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 
-	static cmdInvoke(def op, def params) {
-		println "Invoking the following operation: $op"
+	void cmdInvoke(def op, def params) {
+        reader.printString "Invoking the following operation: $op"
 		if (remote) {
 			getClient().invoke(op, params)
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 
-	static cmdPwd() {
-		println "Displaying the current remote path..."
+	void cmdPwd() {
+        reader.printString  "Displaying the current remote path..."
 		if (remote) {
 			String name = (String) getClient().pwd()
-			println name
+            reader.printString  name
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 
-	static cmdSetDomain(def domain) {
-		println "Setting the domain to $domain..."
+	void cmdSetDomain(def domain) {
+        reader.printString  "Setting the domain to $domain..."
 		if (remote) {
 			getClient().setDomain(domain)
 		}
 		else {
-			println Constants.ERROR_NOT_CONNECTED
+            reader.printString  Constants.ERROR_NOT_CONNECTED
 		}
 	}
 }

Added: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy?rev=1299269&view=auto
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy (added)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/CmdShellBuilder.groovy Sat Mar
10 20:43:12 2012
@@ -0,0 +1,18 @@
+package org.apache.kitty
+
+import org.apache.kitty.client.Client
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: ale
+ * Date: 10/03/2012
+ * Time: 20:32
+ * To change this template use File | Settings | File Templates.
+ */
+class CmdShellBuilder {
+
+    CmdShell build() {
+        Client client = new Client()
+        return new CmdShell(client)
+    }
+}

Modified: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy?rev=1299269&r1=1299268&r2=1299269&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy (original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/Main.groovy Sat Mar 10 20:43:12
2012
@@ -53,6 +53,7 @@ class Main {
 			return
 		}
 
-		CmdShell.startShell()
+        CmdShell cmdShell = new CmdShellBuilder().build()
+		cmdShell.startShell()
 	}
 }

Modified: incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Constants.groovy
URL: http://svn.apache.org/viewvc/incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Constants.groovy?rev=1299269&r1=1299268&r2=1299269&view=diff
==============================================================================
--- incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Constants.groovy (original)
+++ incubator/kitty/trunk/src/main/groovy/org/apache/kitty/utils/Constants.groovy Sat Mar
10 20:43:12 2012
@@ -28,19 +28,12 @@ public final class Constants {
      * Too few params error message.
      */
     public static final String ERROR_TOO_FEW_PARAMETERS =
-        "You did not enter all of the required parameters for this command";
+        'You did not enter all of the required parameters for this command'
 
     /**
      * Not connected error msg.
      */
     public static final String ERROR_NOT_CONNECTED =
-        "Not currently connected to a host";
-
-    /**
-     *
-     */
-    private Constants() {
-        super();
-    }
+        'Not currently connected to a host'
 
 }



Mime
View raw message