accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [1/3] git commit: ACCUMULO-1899 exit with non-zero exit code if there's an error parsing the arguments.
Date Mon, 25 Nov 2013 04:18:01 GMT
Updated Branches:
  refs/heads/master cf3e1fe75 -> e01de2f7f


ACCUMULO-1899 exit with non-zero exit code if there's an error parsing the arguments.

Signed-off-by: Josh Elser <elserj@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/100e75be
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/100e75be
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/100e75be

Branch: refs/heads/master
Commit: 100e75bece15ad2d223070912854430d078e587a
Parents: e6e1df4
Author: Morgan Haskel <morgan.haskel@gmail.com>
Authored: Sun Nov 24 22:43:36 2013 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Sun Nov 24 23:01:15 2013 -0500

----------------------------------------------------------------------
 .../java/org/apache/accumulo/core/cli/Help.java | 14 ++++--
 .../org/apache/accumulo/core/cli/TestHelp.java  | 46 ++++++++++++++++++++
 2 files changed, 57 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/100e75be/core/src/main/java/org/apache/accumulo/core/cli/Help.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/cli/Help.java b/core/src/main/java/org/apache/accumulo/core/cli/Help.java
index dc4ead9..b5b16bc 100644
--- a/core/src/main/java/org/apache/accumulo/core/cli/Help.java
+++ b/core/src/main/java/org/apache/accumulo/core/cli/Help.java
@@ -34,12 +34,20 @@ public class Help {
       commander.parse(args);
     } catch (ParameterException ex) {
       commander.usage();
-      System.err.println(ex.getMessage());
-      System.exit(0);
+      exitWithError(ex.getMessage(), 1);
     }
     if (help) {
       commander.usage();
-      System.exit(0);
+      exit(0);
     }
   }
+  
+  public void exit(int status) {
+    System.exit(status);
+  }
+  
+  public void exitWithError(String message, int status) {
+    System.err.println(message);
+    exit(status);
+  }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/100e75be/core/src/test/java/org/apache/accumulo/core/cli/TestHelp.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/cli/TestHelp.java b/core/src/test/java/org/apache/accumulo/core/cli/TestHelp.java
new file mode 100644
index 0000000..7b29986
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/cli/TestHelp.java
@@ -0,0 +1,46 @@
+package org.apache.accumulo.core.cli;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+public class TestHelp {
+  protected class HelpStub extends Help {
+    @Override
+    public void parseArgs(String programName, String[] args, Object ... others) {
+      super.parseArgs(programName, args, others);
+    }
+
+    @Override
+    public void exit(int status) {
+      throw new RuntimeException(Integer.toString(status));
+    }
+  }
+  
+  @Test
+  public void testInvalidArgs() {
+    String[] args = {"foo"};
+    HelpStub help = new HelpStub();
+    try {
+      help.parseArgs("program", args);
+    } catch (RuntimeException e) {
+      assertEquals("1", e.getMessage());
+    }
+  }
+
+}


Mime
View raw message