[Swift-commit] cog r4021

swift at ci.uchicago.edu swift at ci.uchicago.edu
Fri Jul 11 22:45:03 CDT 2014


------------------------------------------------------------------------
r4021 | hategan | 2014-07-11 22:40:56 -0500 (Fri, 11 Jul 2014) | 1 line

added hidden option to argument parser and made optional things more obvious in usage()
------------------------------------------------------------------------
Index: modules/util/src/org/globus/cog/util/ArgumentParser.java
===================================================================
--- modules/util/src/org/globus/cog/util/ArgumentParser.java	(revision 4020)
+++ modules/util/src/org/globus/cog/util/ArgumentParser.java	(working copy)
@@ -26,6 +26,8 @@
 
 	public static final String DEFAULT = null;
 
+    public static final int HIDDEN = 4;
+
 	private Map<String, String> options;
 
 	private Map<String, String> aliases;
@@ -66,6 +68,10 @@
 	public void addFlag(String name) {
 		addOption(name, FLAG + OPTIONAL);
 	}
+	
+	public void addHiddenFlag(String name) {
+        addOption(name, FLAG + OPTIONAL + HIDDEN);
+    }
 
 	public void addOption(String name, String detail, String argName, int type) {
 		if (options.containsKey(name)) {
@@ -129,7 +135,7 @@
 
 	public int getIntValue(String name) throws NumberFormatException {
 		try {
-			return new Integer(getStringValue(name)).intValue();
+			return Integer.parseInt(getStringValue(name));
 		}
 		catch (Exception e) {
 			throw new NumberFormatException("Invalid numeric value: " + getStringValue(name));
@@ -144,7 +150,25 @@
 			return defaultValue;
 		}
 	}
+	
+	public double getFloatValue(String name) throws NumberFormatException {
+        try {
+            return Double.parseDouble(getStringValue(name));
+        }
+        catch (Exception e) {
+            throw new NumberFormatException("Invalid float value: " + getStringValue(name));
+        }
+    }
 
+    public double getFloatValue(String name, double defaultValue) throws NumberFormatException {
+        if (hasValue(name)) {
+            return getFloatValue(name);
+        }
+        else {
+            return defaultValue;
+        }
+    }
+
 	public boolean isPresent(String name) {
 		return flags.contains(name);
 	}
@@ -166,6 +190,10 @@
 	protected boolean isOptional(String name) {
 		return hasOption(name, OPTIONAL);
 	}
+	
+	protected boolean isHidden(String name) {
+        return hasOption(name, HIDDEN);
+    }
 
 	protected boolean isFlag(String name) {
 		return hasOption(name, FLAG);
@@ -248,11 +276,24 @@
 		System.out.println("Usage:");
 		if (options.containsKey(DEFAULT)) {
 			if (arguments != null) {
-				System.out.println("  " + executableName + " <options> " + getArgumentName(DEFAULT)
-						+ " <arguments>");
+			    if (isOptional(DEFAULT)) {
+			        System.out.println("  " + executableName + " <options> [" + 
+			                getArgumentName(DEFAULT) + " <arguments>]");
+			    }
+			    else {
+			        System.out.println("  " + executableName + " <options> " + 
+                            getArgumentName(DEFAULT) + " <arguments>");
+			    }
 			}
 			else {
-				System.out.println("  " + executableName + " <options> " + getArgumentName(DEFAULT));
+			    if (isOptional(DEFAULT)) {
+			        System.out.println("  " + executableName + " <options> [" + 
+			                getArgumentName(DEFAULT) + "]");
+			    }
+			    else {
+			        System.out.println("  " + executableName + " <options> " + 
+                            getArgumentName(DEFAULT));
+			    }
 			}
 		}
 		else {
@@ -264,6 +305,9 @@
 			if (name == DEFAULT) {
 				continue;
 			}
+			if (isHidden(name)) {
+			    continue;
+			}
 			if (isOptional(name)) {
 				fullName += "[";
 			}



More information about the Swift-commit mailing list