diff --git a/java/src/to/mmo/cmdlineoptions/CmdOptions.java b/java/src/to/mmo/cmdlineoptions/CmdOptions.java index 046f1a0..1fa46cc 100644 --- a/java/src/to/mmo/cmdlineoptions/CmdOptions.java +++ b/java/src/to/mmo/cmdlineoptions/CmdOptions.java @@ -17,15 +17,22 @@ public class CmdOptions { private static CmdOptions instance; + private static String optionChar; + + private boolean combineSwitches; + public static class Option { private String name; private ArrayList cmd; + private ArrayList cmdLong; private String description; private ArrayList defaultParameter; private ArrayList possibleParams; private boolean set; private ArrayList values; + private int maxParameters, minParameters; + private ArrayList examples; public ArrayList getValues() { return values; @@ -38,15 +45,26 @@ public class CmdOptions { public Option() { values = new ArrayList(); cmd = new ArrayList(); + cmdLong = new ArrayList(); defaultParameter = new ArrayList(); possibleParams = new ArrayList(); + examples = new ArrayList(); } public Option addCommand(String cmd) { + if (cmd.contains(optionChar)) + cmd.replaceAll(optionChar, ""); this.cmd.add(cmd); return this; } + public Option addLongCommand(String cmd) { + if (cmd.contains(optionChar)) + cmd.replaceAll(optionChar, ""); + this.cmdLong.add(cmd); + return this; + } + public Option addDefaultParameter(String d) { this.defaultParameter.add(d); return this; @@ -71,6 +89,12 @@ public class CmdOptions { return this; } + public Option setParameterCount(int min, int max) { + this.minParameters = min; + this.maxParameters = max; + return this; + } + public String getDescription() { return description; } @@ -97,6 +121,11 @@ public class CmdOptions { return this; } + public Option addExample(String example) { + this.examples.add(example); + return this; + } + public String toString() { String ret = name + " ("; for (String s : cmd) { @@ -135,6 +164,8 @@ public class CmdOptions { private HashMap options; private CmdOptions() { + optionChar = "-"; + this.setSwitchCombination(false); options = new HashMap(); this.createOption("help") .setDescription( @@ -149,6 +180,20 @@ public class CmdOptions { return instance; } + public void setSwitchCombination(boolean on) { + this.combineSwitches = on; + } + + public void setOptionCharacter(String c) { + this.optionChar = c; + } + + public void setHelpGeneration(boolean on) { + if (!on) { + options.remove("help"); + } + } + public Option createOption(String name) { Option o = new Option(); o.setName(name); @@ -156,6 +201,10 @@ public class CmdOptions { return o; } + public Option getBareOption(String name) { + return options.get(name); + } + public String[] get(String name) { return getOption(name); } @@ -192,6 +241,14 @@ public class CmdOptions { return null; } + public Integer getOptionAsInt(String name, int index) { + Integer[] array = getOptionAsInt(name); + if (index >= 0 && index < array.length) { + return array[index]; + } + return null; + } + public Double[] getOptionAsDouble(String name) { if (options.get(name).values.size() > 0) { ArrayList list = new ArrayList(); @@ -209,17 +266,20 @@ public class CmdOptions { return null; } + public Double getOptionAsDouble(String name, int index) { + Double[] array = getOptionAsDouble(name); + if (index >= 0 && index < array.length) { + return array[index]; + } + return null; + } + public boolean isSet(String option) { return options.get(option).set; } public boolean isSet(String option, String parameter) { - for (String o : options.get(option).values) { - if (o.equals(parameter)) { - return true; - } - } - return false; + return this.getValuesAsList(option).contains(parameter); } public String toString(boolean help) {