You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2015/07/28 23:04:05 UTC

svn commit: r1693161 - in /devicemap/trunk/clients/2.0/reference: run.sh src/DeviceMapClient.java

Author: rezan
Date: Tue Jul 28 21:04:05 2015
New Revision: 1693161

URL: http://svn.apache.org/r1693161
Log:
parameters

Modified:
    devicemap/trunk/clients/2.0/reference/run.sh
    devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java

Modified: devicemap/trunk/clients/2.0/reference/run.sh
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/run.sh?rev=1693161&r1=1693160&r2=1693161&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/run.sh (original)
+++ devicemap/trunk/clients/2.0/reference/run.sh Tue Jul 28 21:04:05 2015
@@ -8,4 +8,4 @@ fi
 
 cd bin
 
-java DeviceMapClient
+java DeviceMapClient "$@"

Modified: devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java?rev=1693161&r1=1693160&r2=1693161&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Tue Jul 28 21:04:05 2015
@@ -17,8 +17,81 @@
  under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class DeviceMapClient {
-  public static void main(String args[]) {
-    System.out.println("DeviceMapClient");
+  
+  public final static String VERSION = "2.0";
+
+  public static void main(String args[]) throws Exception {
+    System.out.println("DeviceMap Reference Client " + VERSION);
+
+    List<String> patterns = new ArrayList<String>();
+    List<String> attributes = new ArrayList<String>();
+    List<String> tests = new ArrayList<String>();
+
+    String testString = null;
+
+    for(int i = 0; i < args.length; i++) {
+      String option = args[i];
+
+      if(option.startsWith("-h")) {
+        printHelp();
+        return;
+      } else if(option.equals("-p")) {
+        patterns.add(getParam(args, ++i, "-t file parameter missing"));
+      } else if(option.equals("-a")) {
+        attributes.add(getParam(args, ++i, "-t file parameter missing"));
+      } else if(option.equals("-t")) {
+        tests.add(getParam(args, ++i, "-t file parameter missing"));
+      } else if(!option.startsWith("-") && testString == null) {
+        testString = option;
+      } else {
+        printHelp();
+        throw new Exception("unknown option: " + option);
+      }
+    }
+
+    if(patterns.isEmpty()) {
+      printHelp();
+      throw new Exception("Pattern file required");
+    }
+
+    for(String pattern : patterns) {
+      System.out.println("Pattern file: '" + pattern + "'");
+    }
+
+    for(String attribute : attributes) {
+      System.out.println("Attribute file: '" + attribute + "'");
+    }
+
+    for(String test : tests) {
+      System.out.println("Test file: '" + test + "'");
+    }
+
+    if(testString != null) {
+      System.out.println("Test string: '" + testString + "'");
+    }
+  }
+
+  private static void printHelp() {
+    System.out.println("Usage: " + DeviceMapClient.class.getName() + " [OPTIONS] [STRING]\n");
+    System.out.println("  -p <file>            load DeviceMap 2.0 pattern file (REQUIRED)");
+    System.out.println("  -a <file>            load DeviceMap 2.0 attribute file");
+    System.out.println("  -t <file>            load DeviceMap 2.0 test file");
+    System.out.println("  -h                   print help");
+    System.out.println("  STRING               test string");
+    System.out.println("");
+  }
+
+  private static String getParam(String args[], int pos, String error) throws Exception {
+    if(pos >= args.length) {
+      throw new Exception(error);
+    } else if(args[pos].startsWith("-") || args[pos].isEmpty()) {
+      throw new Exception(error);
+    } else {
+      return args[pos];
+    }
   }
 }