geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r406798 - in /geronimo/sandbox/gshell/trunk: gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/ gshell-core...
Date Tue, 16 May 2006 01:43:12 GMT
Author: jdillon
Date: Mon May 15 18:43:11 2006
New Revision: 406798

URL: http://svn.apache.org/viewcvs?rev=406798&view=rev
Log:
Added uber simple set command

Added:
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SetCommand.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java

Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SetCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SetCommand.java?rev=406798&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SetCommand.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SetCommand.java
Mon May 15 18:43:11 2006
@@ -0,0 +1,114 @@
+/*
+ * 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.commands.standard;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.PosixParser;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.HelpFormatter;
+
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.console.IO;
+
+/**
+ * ???
+ *
+ * @version $Id: CatCommand.java 399599 2006-05-04 08:13:57Z jdillon $
+ */
+public class SetCommand
+    extends CommandSupport
+{
+    public SetCommand() {
+        super("set");
+    }
+
+    protected int doExecute(final String[] args) throws Exception {
+        assert args != null;
+
+        //
+        // TODO: Optimize, move common code to CommandSupport
+        //
+
+        IO io = getIO();
+
+        Options options = new Options();
+
+        options.addOption(OptionBuilder.withLongOpt("help")
+            .withDescription("Display this help message")
+            .create('h'));
+
+        CommandLineParser parser = new PosixParser();
+        CommandLine line = parser.parse(options, args);
+
+        if (line.hasOption('h')) {
+            io.out.println(getName() + " -- set a variable or property");
+            io.out.println();
+
+            HelpFormatter formatter = new HelpFormatter();
+            formatter.printHelp(
+                io.out,
+                80, // width (FIXME: Should pull from gshell.columns variable)
+                getName() + " [options] <name=value>",
+                "",
+                options,
+                4, // left pad
+                4, // desc pad
+                "",
+                false); // auto usage
+
+            io.out.println();
+
+            return Command.SUCCESS;
+        }
+
+        String[] _args = line.getArgs();
+        if (args.length != 1) {
+            log.error("Expected one and only one argument.");
+        }
+        else {
+            //
+            // TODO: Support setting context variables
+            //
+            
+            setPropertyFrom(_args[0]);
+        }
+
+        return Command.SUCCESS;
+    }
+
+    private void setPropertyFrom(final String namevalue) {
+        String name, value;
+        int j = namevalue.indexOf("=");
+
+        if (j == -1) {
+            name = namevalue;
+            value = "true";
+        }
+        else {
+            name = namevalue.substring(0, j);
+            value = namevalue.substring(j + 1, namevalue.length());
+        }
+        name = name.trim();
+
+        log.info("Setting system property: " + name + "=" + value);
+
+        System.setProperty(name, value);
+    }
+}

Modified: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml?rev=406798&r1=406797&r2=406798&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml
Mon May 15 18:43:11 2006
@@ -9,11 +9,9 @@
     </bean>
     
     <bean id="echo" class="org.apache.geronimo.gshell.commands.standard.EchoCommand" singleton="false">
-        <property name="name" value="echo"/>
     </bean>
     
     <bean id="cat" class="org.apache.geronimo.gshell.commands.standard.CatCommand" singleton="false">
-        <property name="name" value="cat"/>
     </bean>
 
     <bean id="java" class="org.apache.geronimo.gshell.commands.standard.JavaCommand" singleton="false">
@@ -23,6 +21,9 @@
     </bean>
 
     <bean id="help" class="org.apache.geronimo.gshell.commands.standard.HelpCommand" singleton="false">
+    </bean>
+
+    <bean id="set" class="org.apache.geronimo.gshell.commands.standard.SetCommand" singleton="false">
     </bean>
 
 </beans>

Modified: 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=406798&r1=406797&r2=406798&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
Mon May 15 18:43:11 2006
@@ -29,6 +29,7 @@
  * @version $Id: IO.java 399599 2006-05-04 08:13:57Z jdillon $
  */
 public class InteractiveConsole
+    implements Runnable
 {
     private static final Log log = LogFactory.getLog(InteractiveConsole.class);
 
@@ -55,6 +56,11 @@
 
                 while ((line = readLine("> ")) != null) {
                     log.debug("Read line: " + line);
+
+                    // Just ignore blank lines
+                    if (line.trim().equals("")) {
+                        continue;
+                    }
 
                     int result = gshell.execute(line);
 



Mime
View raw message