X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=third-party%2Fopenflow-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fcodec%2Fexample%2Fcli%2FSimpleCLI.java;fp=third-party%2Fopenflow-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenflow%2Fcodec%2Fexample%2Fcli%2FSimpleCLI.java;h=0000000000000000000000000000000000000000;hb=64fe0fbca1a6c2b77ad25f568d73a7eb64236d16;hp=263b29ca42dde8a21cd066b0bc8f2d6a5457a025;hpb=8b9a3ff2bbc83941254b46b818cbbae5cc1a3a5b;p=openflowjava.git diff --git a/third-party/openflow-codec/src/main/java/org/openflow/codec/example/cli/SimpleCLI.java b/third-party/openflow-codec/src/main/java/org/openflow/codec/example/cli/SimpleCLI.java deleted file mode 100644 index 263b29ca..00000000 --- a/third-party/openflow-codec/src/main/java/org/openflow/codec/example/cli/SimpleCLI.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.openflow.codec.example.cli; - -import java.io.PrintStream; - -/** - * Very basic command line interface - * - * (really should be something in java.* for this; only implementing this to - * remove external dependencies) - * - * Modeled after org.apache.common.cli . - * - * @author Rob Sherwood (rob.sherwood@stanford.edu) - * - */ - -public class SimpleCLI { - - private static final String NAME_WIDTH = "-15"; - private static final String VALUE_WIDTH = "-20"; - private static final String FORMAT_STRING = "%1$" + NAME_WIDTH + "s%2$" + VALUE_WIDTH + "s%3$s\n"; - Options options; - - int optind; - - /** - * Need to use SimpleCLI.parse() instead - * - * @param options - */ - - private SimpleCLI(Options options) { - this.options = options; - } - - /** - * @return the index of the last parsed option - * - * Useful for finding options that don't start with "-" or "--" - */ - public int getOptind() { - return optind; - } - - /** - * @param optind - * the optind to set - */ - public void setOptind(int optind) { - this.optind = optind; - } - - public boolean hasOption(String shortName) { - Option option = this.options.getOption(shortName); - if (option == null) - return false; - return option.specified; - } - - public String getOptionValue(String shortName) { - Option option = this.options.getOption(shortName); - if (option == null) - return null; - if (!option.specified) - return option.defaultVal.toString(); - else - return option.val; - } - - public static SimpleCLI parse(Options options, String[] args) throws ParseException { - SimpleCLI simpleCLI = new SimpleCLI(options); - int i; - for (i = 0; i < args.length; i++) { - if (!args[i].startsWith("-")) - break; // not a short or long option - String optName = args[i].replaceFirst("^-*", ""); // remove leading - // "--" - Option option; - if (args[i].startsWith("--")) - option = options.getOptionByLongName(optName); - else - option = options.getOption(optName); - if (option == null) - throw new ParseException("unknown option: " + optName); - option.specified = true; - if (option.needsArg()) { - if ((i + 1) >= args.length) - throw new ParseException("option " + optName + " requires an argument:: " + option.comment); - option.val = args[i + 1]; - i++; // skip next element; we've parsed it - } - } - simpleCLI.setOptind(i); - return simpleCLI; - } - - public static void printHelp(String canonicalName, Options options) { - printHelp(canonicalName, options, System.err); - } - - private static void printHelp(String helpString, Options options, PrintStream err) { - err.println(helpString); - err.format(FORMAT_STRING, "\toption", "type [default]", "usage"); - for (Option option : options.getOptions()) { - String msg = "\t"; - if (option.shortOpt != null) - msg += "-" + option.shortOpt; - if (option.longOpt != null) { - if (!msg.equals("\t")) - msg += "|"; - msg += "--" + option.longOpt; - } - String val = ""; - if (option.defaultVal != null) - val += option.defaultVal.getClass().getSimpleName() + " [" + option.defaultVal.toString() + "]"; - String comment; - if (option.comment != null) - comment = option.comment; - else - comment = ""; - - err.format(FORMAT_STRING, msg, val, comment); - } - err.println(""); // print blank line at the end, to look pretty - } - -}