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 03:14:26 UTC

svn commit: r406792 - in /geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main: java/org/apache/geronimo/gshell/commands/standard/ resources/META-INF/org.apache.geronimo.gshell/

Author: jdillon
Date: Mon May 15 18:14:25 2006
New Revision: 406792

URL: http://svn.apache.org/viewcvs?rev=406792&view=rev
Log:
Added exit command to simply exit the jvm
Added help command which currently just lists all registered commands

Added:
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ExitCommand.java
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell/components.xml

Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ExitCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ExitCommand.java?rev=406792&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ExitCommand.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/ExitCommand.java Mon May 15 18:14:25 2006
@@ -0,0 +1,111 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+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.commons.lang.StringUtils;
+
+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 ExitCommand
+    extends CommandSupport
+{
+    public ExitCommand() {
+        super("exit");
+    }
+
+    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'));
+
+        options.addOption(OptionBuilder.withLongOpt("code")
+            .withDescription("Use the give exit code")
+            .hasArg()
+            .create('c'));
+
+        CommandLineParser parser = new PosixParser();
+        CommandLine line = parser.parse(options, args);
+
+        if (line.hasOption('h')) {
+            io.out.println(getName() + " -- exit the virtual machine");
+            io.out.println();
+
+            HelpFormatter formatter = new HelpFormatter();
+            formatter.printHelp(
+                io.out,
+                80, // width (FIXME: Should pull from gshell.columns variable)
+                getName() + " [options]",
+                "",
+                options,
+                4, // left pad
+                4, // desc pad
+                "",
+                false); // auto usage
+
+            io.out.println();
+
+            return Command.SUCCESS;
+        }
+
+        // Get the status code to exit with
+        int exitCode = 0;
+        if (line.hasOption('c')) {
+            String value = line.getOptionValue('c');
+            exitCode = Integer.parseInt(value);
+        }
+
+        exit(exitCode);
+
+        // Should never get this far
+        assert false;
+
+        return Command.FAILURE;
+    }
+
+    private void exit(final int exitCode) {
+        log.info("Exiting w/code: " + exitCode);
+        System.exit(exitCode);
+    }
+}

Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java?rev=406792&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/HelpCommand.java Mon May 15 18:14:25 2006
@@ -0,0 +1,121 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Iterator;
+
+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.commons.lang.StringUtils;
+
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandSupport;
+import org.apache.geronimo.gshell.console.IO;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationContext;
+import org.springframework.beans.BeansException;
+
+/**
+ * ???
+ *
+ * @version $Id: CatCommand.java 399599 2006-05-04 08:13:57Z jdillon $
+ */
+public class HelpCommand
+    extends CommandSupport
+    implements ApplicationContextAware
+{
+    public HelpCommand() {
+        super("help");
+    }
+
+    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() + " -- display gshell help");
+            io.out.println();
+
+            HelpFormatter formatter = new HelpFormatter();
+            formatter.printHelp(
+                io.out,
+                80, // width (FIXME: Should pull from gshell.columns variable)
+                getName() + " [options]",
+                "",
+                options,
+                4, // left pad
+                4, // desc pad
+                "",
+                false); // auto usage
+
+            io.out.println();
+
+            return Command.SUCCESS;
+        }
+
+        //
+        // HACK: For now just list all know commands
+        //
+
+        Map commands = ctx.getBeansOfType(Command.class);
+        Iterator iter = commands.keySet().iterator();
+
+        while (iter.hasNext()) {
+            String name = (String)iter.next();
+            Command cmd = (Command)commands.get(name);
+
+            io.out.println(name);
+        }
+
+        return Command.SUCCESS;
+    }
+
+    //
+    // ApplicationContextAware
+    //
+
+    private ApplicationContext ctx;
+
+    public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
+        assert applicationContext != null;
+
+        this.ctx = applicationContext;
+    }
+}

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=406792&r1=406791&r2=406792&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:14:25 2006
@@ -19,4 +19,10 @@
     <bean id="java" class="org.apache.geronimo.gshell.commands.standard.JavaCommand" singleton="false">
     </bean>
 
+    <bean id="exit" class="org.apache.geronimo.gshell.commands.standard.ExitCommand" singleton="false">
+    </bean>
+
+    <bean id="help" class="org.apache.geronimo.gshell.commands.standard.HelpCommand" singleton="false">
+    </bean>
+
 </beans>