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/06/01 18:26:45 UTC
svn commit: r410881 - 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.command/
gsh...
Author: jdillon
Date: Thu Jun 1 09:26:42 2006
New Revision: 410881
URL: http://svn.apache.org/viewvc?rev=410881&view=rev
Log:
Added sleep command
Fixed bug in exit
Added:
geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java (with props)
geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties (with props)
Modified:
geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtin/ExitCommand.java
Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java?rev=410881&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java Thu Jun 1 09:26:42 2006
@@ -0,0 +1,104 @@
+/*
+ * 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.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;
+
+/**
+ * Sleep... zzzZ
+ *
+ * @version $Id$
+ */
+public class SleepCommand
+ extends CommandSupport
+{
+ public SleepCommand() {
+ super("sleep");
+ }
+
+ 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;
+ long time = -1;
+
+ if (args.length != 1) {
+ usage = true;
+ }
+ else {
+ time = Long.parseLong(args[0]);
+ }
+
+ if (usage || line.hasOption('h')) {
+ io.out.println(getName() + " -- sleep... zzzZ");
+ io.out.println();
+
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp(
+ io.out,
+ 80, // width (FIXME: Should pull from gshell.columns variable)
+ getName() + " [options] <time>",
+ "",
+ options,
+ 4, // left pad
+ 4, // desc pad
+ "",
+ false); // auto usage
+
+ io.out.println();
+
+ return Command.SUCCESS;
+ }
+
+ log.info("Sleeping for " + time);
+
+ try {
+ Thread.sleep(time);
+ }
+ catch (InterruptedException ignore) {
+ log.debug("Sleep was interrupted... :-(");
+ }
+
+ log.info("Awake now");
+
+ return Command.SUCCESS;
+ }
+}
Propchange: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/java/org/apache/geronimo/gshell/commands/standard/SleepCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties?rev=410881&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties (added)
+++ geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties Thu Jun 1 09:26:42 2006
@@ -0,0 +1,11 @@
+##
+## $Id$
+##
+
+class=org.apache.geronimo.gshell.commands.standard.SleepCommand
+
+name=sleep
+
+# aliases=
+
+category=standard
Propchange: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/sandbox/gshell/trunk/gshell-commands/standard-commands/src/main/resources/META-INF/org.apache.geronimo.gshell.command/sleep.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtin/ExitCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtin/ExitCommand.java?rev=410881&r1=410880&r2=410881&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtin/ExitCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/commands/builtin/ExitCommand.java Thu Jun 1 09:26:42 2006
@@ -40,7 +40,7 @@
super("exit");
}
- protected int doExecute(final String[] args) throws Exception {
+ protected int doExecute(String[] args) throws Exception {
assert args != null;
//
@@ -57,6 +57,7 @@
CommandLineParser parser = new PosixParser();
CommandLine line = parser.parse(options, args);
+ args = line.getArgs();
boolean usage = false;
int exitCode = 0;
@@ -92,7 +93,7 @@
}
exit(exitCode);
-
+
// Should never get this far
assert false;