Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 6549 invoked from network); 1 Jun 2006 16:33:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Jun 2006 16:33:43 -0000 Received: (qmail 60668 invoked by uid 500); 1 Jun 2006 16:33:43 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 60618 invoked by uid 500); 1 Jun 2006 16:33:42 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 60599 invoked by uid 99); 1 Jun 2006 16:33:42 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jun 2006 09:33:42 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jun 2006 09:33:41 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 8D5BE1A983A; Thu, 1 Jun 2006 09:33:21 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060601163321.8D5BE1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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