geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r410883 - in /geronimo/sandbox/gshell/trunk/gshell-core/src/main: java/org/apache/geronimo/gshell/builtins/ java/org/apache/geronimo/gshell/commands/ resources/META-INF/org.apache.geronimo.gshell.command/
Date Thu, 01 Jun 2006 16:33:21 GMT
Author: jdillon
Date: Thu Jun  1 09:33:20 2006
New Revision: 410883

URL: http://svn.apache.org/viewvc?rev=410883&view=rev
Log:
Moved

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
  (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/
Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/exit.properties

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java?rev=410883&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/builtins/ExitCommand.java
Thu Jun  1 09:33:20 2006
@@ -0,0 +1,112 @@
+/*
+ * 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.console.IO;
+import org.apache.geronimo.gshell.ExitNotification;
+import org.apache.geronimo.gshell.util.Arguments;
+
+/**
+ * Exit the current shell.
+ *
+ * @version $Id$
+ */
+public class ExitCommand
+    extends CommandSupport
+{
+    public ExitCommand() {
+        super("exit");
+    }
+
+    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'));
+
+        CommandLineParser parser = new PosixParser();
+        CommandLine line = parser.parse(options, args);
+        args = line.getArgs();
+
+        boolean usage = false;
+        int exitCode = 0;
+
+        if (args.length > 1) {
+            io.err.println("Unexpected arguments: " + Arguments.asString(args));
+            io.err.println();
+            usage = true;
+        }
+        if (args.length == 1) {
+            exitCode = Integer.parseInt(args[0]);
+        }
+
+        if (usage || line.hasOption('h')) {
+            io.out.println(getName() + " -- exit the current shell");
+            io.out.println();
+
+            HelpFormatter formatter = new HelpFormatter();
+            formatter.printHelp(
+                io.out,
+                80, // width (FIXME: Should pull from gshell.columns variable)
+                getName() + " [options] [code]",
+                "",
+                options,
+                4, // left pad
+                4, // desc pad
+                "",
+                false); // auto usage
+
+            io.out.println();
+
+            return Command.SUCCESS;
+        }
+
+        exit(exitCode);
+
+        // Should never get this far
+        assert false;
+
+        return Command.FAILURE;
+    }
+
+    private void exit(final int exitCode) {
+        log.info("Exiting w/code: " + exitCode);
+
+        //
+        // DO NOT Call System.exit() !!!
+        //
+
+        throw new ExitNotification(exitCode);
+    }
+}

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

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

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

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/exit.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/exit.properties?rev=410883&r1=410882&r2=410883&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/exit.properties
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/resources/META-INF/org.apache.geronimo.gshell.command/exit.properties
Thu Jun  1 09:33:20 2006
@@ -2,7 +2,7 @@
 ## $Id:exit.properties 410870 2006-06-01 07:43:42 -0700 (Thu, 01 Jun 2006) jdillon $
 ##
 
-class=org.apache.geronimo.gshell.commands.builtin.ExitCommand
+class=org.apache.geronimo.gshell.builtins.ExitCommand
 
 name=exit
 



Mime
View raw message