You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/05/16 02:41:19 UTC

svn commit: r406786 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-core/src/main/java/org/apache/geronimo/gshell/ gshell-core/src/main/java/org/apache/geronimo/gshell/console/

Author: jdillon
Date: Mon May 15 17:41:19 2006
New Revision: 406786

URL: http://svn.apache.org/viewcvs?rev=406786&view=rev
Log:
Uber trival implemenation of the interactive console

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=406786&r1=406785&r2=406786&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java Mon May 15 17:41:19 2006
@@ -27,6 +27,7 @@
 
 import org.apache.geronimo.gshell.GShell;
 import org.apache.geronimo.gshell.console.IO;
+import org.apache.geronimo.gshell.console.InteractiveConsole;
 
 import org.apache.geronimo.gshell.util.Version;
 import org.apache.geronimo.gshell.util.Banner;
@@ -185,19 +186,19 @@
         }
 
         if (interactive) {
-            //
-            // TODO: Need to check if there are args, and run them and then enter interactive
-            //
-            throw new Error("Interative mode not implemented... yet");
+            InteractiveConsole console = new InteractiveConsole(io, gshell);
+
+            // Check if there are args, and run them and then enter interactive
+            if (_args.length != 0) {
+                gshell.execute(_args);
+            }
+
+            console.run();
         }
         else {
             int status = gshell.execute(_args);
             System.exit(status);
         }
-
-        //
-        // TODO: Run interactive
-        //
     }
     
     public static void main(final String[] args, final ClassWorld world) throws Exception {

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java?rev=406786&r1=406785&r2=406786&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/GShellImpl.java Mon May 15 17:41:19 2006
@@ -49,9 +49,19 @@
     }
     
     public int execute(final String commandline) throws Exception {
+        assert commandline != null;
+
         log.info("Executing (String): " + commandline);
+
+        //
+        // HACK: Just to get something to work...
+        //
         
-        throw new Error("Not implemented, pending some parser work");
+        String[] args = commandline.split("\\s");
+        String name = args[0];
+        args = Arguments.shift(args);
+
+        return execute(name, args);
     }
     
     public int execute(final String commandName, String[] args) throws Exception {
@@ -98,7 +108,7 @@
         
         return execute(args[0], Arguments.shift(args));
     }
-    
+
     //
     // ApplicationContextAware
     //

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java?rev=406786&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java Mon May 15 17:41:19 2006
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.gshell.console;
+
+import org.apache.geronimo.gshell.GShell;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+
+/**
+ * ???
+ *
+ * @version $Id: IO.java 399599 2006-05-04 08:13:57Z jdillon $
+ */
+public class InteractiveConsole
+{
+    private static final Log log = LogFactory.getLog(InteractiveConsole.class);
+
+    private GShell gshell;
+    private IO io;
+    private BufferedReader reader;
+
+    public InteractiveConsole(final IO io, final GShell gshell) {
+        assert io != null;
+        assert gshell != null;
+
+        this.io = io;
+        this.gshell = gshell;
+
+        reader = new BufferedReader(io.in);
+    }
+
+    public void run() {
+        log.info("Running...");
+
+        try {
+            String line;
+
+            //
+            // TODO: Need some prompting support
+            //
+
+            io.out.print("> ");
+            io.out.flush();
+
+            while ((line = readLine()) != null) {
+                log.debug("Read line: " + line);
+
+                int result = gshell.execute(line);
+
+                //
+                // ???
+                //
+
+                io.out.print("> ");
+                io.out.flush();
+            }
+
+        }
+        catch (Exception e) {
+            log.error("Unhandled failure", e);
+        }
+    }
+
+    private String readLine() throws IOException {
+        return reader.readLine();
+    }
+}