geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r411412 - in /geronimo/sandbox/gshell/trunk: ./ gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/
Date Sat, 03 Jun 2006 09:44:48 GMT
Author: jdillon
Date: Sat Jun  3 02:44:47 2006
New Revision: 411412

URL: http://svn.apache.org/viewvc?rev=411412&view=rev
Log:
Adding unset command
Set command w/o args shows all set variables & their values

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
  (with props)
Modified:
    geronimo/sandbox/gshell/trunk/NOTES.txt
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java

Modified: geronimo/sandbox/gshell/trunk/NOTES.txt
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/NOTES.txt?rev=411412&r1=411411&r2=411412&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/NOTES.txt (original)
+++ geronimo/sandbox/gshell/trunk/NOTES.txt Sat Jun  3 02:44:47 2006
@@ -7,6 +7,20 @@
 
  ----
 
+Variable support, expressions... should the parser do this?
+    Parse out ${...}, then use Jexl or something to eval?
+    Should "xxx ${...} yyy" also be handled by parser... or sub parse by string node when
visited?
+
+Switch to Object execute(String name, Object...)
+
+Hook up backtick and execute assign bits... foo=`echo bar`
+    Dunno if this captures the output of 'echo bar' or the return of the command
+    Might need to have both?
+
+    Once object are in and out, this will open up a bunch of op to do fancy stuff.
+
+ * * *
+
 enable/disable categories.  Command def sets the initial state, 'enable' command
     toggles to enable or disable categories:
 
@@ -16,11 +30,6 @@
 "*" means global for category
 
 Command search path (required for above)
-
- * * *
-
-Settings, read from ~/.gshell/...
-
     ~/.gshell/
         profile.gsh
         settings.gsh?  settings.properties?  settings.xml?
@@ -29,6 +38,11 @@
 
  * * *
 
+ * * *
+
+Settings, read from ~/.gshell/...
+
+
 Implement MiniJar to make the gshell dependencies as small as possible,
     will require adding more features to minijar (half tested already)
 
@@ -40,11 +54,15 @@
 
 Refactor output and verbosity filters...
 
-    IO.trace() -vvv
-    IO.debug() -vv
-Add IO.info()  -v
-    IO.warn()  unless -q
-    IO.error()
+        IO.trace() -vvv
+        IO.debug() -vv
+    Add IO.info()  -v
+        IO.warn()  unless -q
+        IO.error()
+
+    This means that IO will need to know the verbosity setting... :-(
+
+    Need methods to handle exceptions too, for remoteness can not use logging for error reporting
 
 ANSI color prompt
 
@@ -55,6 +73,9 @@
 Authenticator for server cmd, maybe for normal too?
 
 SSH support?  Can Jsch do this or not?
+
+Fix the input handing for teling... for some reason input starts with x0 when it shouldn't
+    and using arrows can corrupt... bet these are linked some how
 
  * * *
 

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java?rev=411412&r1=411411&r2=411412&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/SetCommand.java
Sat Jun  3 02:44:47 2006
@@ -27,6 +27,8 @@
 import org.apache.geronimo.gshell.command.Variables;
 import org.apache.geronimo.gshell.console.IO;
 
+import java.util.Iterator;
+
 /**
  * Set a variable or property.
  *
@@ -75,14 +77,7 @@
         CommandLineParser parser = new PosixParser();
         CommandLine line = parser.parse(options, args);
 
-        boolean usage = false;
-        String[] _args = line.getArgs();
-
-        if (_args.length == 0) {
-            usage = true;
-        }
-
-        if (usage || line.hasOption('h')) {
+        if (line.hasOption('h')) {
             io.out.println(getName() + " -- set a variable or property");
             io.out.println();
 
@@ -90,7 +85,7 @@
             formatter.printHelp(
                 io.out,
                 80, // width (FIXME: Should pull from gshell.columns variable)
-                getName() + " [options] (<name=value>)+",
+                getName() + " [options] (<name[=value>])*",
                 "",
                 options,
                 4, // left pad
@@ -103,6 +98,26 @@
             return Command.SUCCESS;
         }
 
+        String[] _args = line.getArgs();
+
+        // No args... list all variables
+        if (_args.length == 0) {
+            Variables vars = getVariables();
+            Iterator<String> iter = vars.names();
+
+            while (iter.hasNext()) {
+                String name = iter.next();
+                Object value = vars.get(name);
+
+                io.out.print(name);
+                io.out.print("=");
+                io.out.print(value);
+                io.out.println();
+            }
+
+            return Command.SUCCESS;
+        }
+
         Mode mode = Mode.VARIABLE;
 
         if (line.hasOption('p')) {
@@ -112,7 +127,7 @@
         //
         // FIXME: This does not jive well with the parser, and stuff like foo = "b a r"
         //
-        
+
         for (String arg : _args) {
             switch (mode) {
                 case PROPERTY:

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java?rev=411412&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
Sat Jun  3 02:44:47 2006
@@ -0,0 +1,136 @@
+/*
+ * 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.builtins;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.console.IO;
+
+/**
+ * Unset a variable or property.
+ *
+ * @version $Id$
+ */
+public class UnsetCommand
+    extends CommandSupport
+{
+    public UnsetCommand() {
+        super("unset");
+    }
+
+    enum Mode
+    {
+        VARIABLE,
+        PROPERTY
+    }
+
+    protected int doExecute(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'));
+
+        options.addOption(OptionBuilder.withLongOpt("property")
+            .withDescription("Unset a system property")
+            .create('p'));
+
+        //
+        // TODO: Add support to unset in parent (parent) scope
+        //
+
+        CommandLineParser parser = new PosixParser();
+        CommandLine line = parser.parse(options, args);
+
+        boolean usage = false;
+        String[] _args = line.getArgs();
+
+        if (_args.length == 0) {
+            usage = true;
+        }
+
+        if (usage || line.hasOption('h')) {
+            io.out.println(getName() + " -- unset 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>)+",
+                "",
+                options,
+                4, // left pad
+                4, // desc pad
+                "",
+                false); // auto usage
+
+            io.out.println();
+
+            return Command.SUCCESS;
+        }
+
+        Mode mode = Mode.VARIABLE;
+
+        if (line.hasOption('p')) {
+            mode = Mode.PROPERTY;
+        }
+
+        for (String arg : _args) {
+            switch (mode) {
+                case PROPERTY:
+                    unsetProperty(arg);
+                    break;
+
+                case VARIABLE:
+                    unsetVariable(arg);
+                    break;
+            }
+        }
+
+        return Command.SUCCESS;
+    }
+
+    private void unsetProperty(final String name) {
+        log.info("Unsetting system property: " + name);
+        System.getProperties().remove(name);
+    }
+
+    private void unsetVariable(final String name) {
+        log.info("Unsetting variable: " + name);
+
+        // Command vars always has a parent, set only makes sence when setting in parent's
scope
+        Variables vars = this.getVariables().parent();
+
+        vars.unset(name);
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/UnsetCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties?rev=411412&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
Sat Jun  3 02:44:47 2006
@@ -0,0 +1,11 @@
+##
+## $Id$
+##
+
+class=org.apache.geronimo.gshell.builtins.UnsetCommand
+
+name=unset
+
+#aliases=
+
+category=builtins

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/unset.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message