package jalview.bin.argparser;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
static
{
- HELP.setOptions(Opt.UNARY);
+ HELP.setOptions("Display this help message", Opt.UNARY, Opt.BOOTSTRAP);
CALCULATION.setOptions(true, Opt.BOOLEAN); // default "true" implies only
- // expecting "--nocalculation"
+ // expecting "--nocalculation"
MENUBAR.setOptions(true, Opt.BOOLEAN);
STATUS.setOptions(true, Opt.BOOLEAN);
SHOWOVERVIEW.setOptions(Opt.UNARY, Opt.LINKED);
private boolean defaultBoolValue = false;
+ private String description = null;
+
private Arg()
{
this(new String[0]);
public String argString()
{
- return new StringBuilder(ArgParser.DOUBLEDASH).append(getName())
- .toString();
+ return argString(false);
+ }
+
+ public String negateArgString()
+ {
+ return argString(true);
+ }
+
+ private String argString(boolean negate)
+ {
+ StringBuilder sb = new StringBuilder(ArgParser.DOUBLEDASH);
+ if (negate && hasOption(Opt.BOOLEAN))
+ sb.append(ArgParser.NEGATESTRING);
+ sb.append(getName());
+ return sb.toString();
}
public String toLongString()
protected void setOptions(Opt... options)
{
- setOptions(false, options);
+ setOptions("", false, options);
+ }
+
+ protected void setOptions(String desc, Opt... options)
+ {
+ setOptions(desc, false, options);
}
protected void setOptions(boolean defaultBoolValue, Opt... options)
{
+ setOptions("", defaultBoolValue, options);
+ }
+
+ protected void setOptions(String desc, boolean defaultBoolValue,
+ Opt... options)
+ {
+ this.description = desc;
this.defaultBoolValue = defaultBoolValue;
- argOptions = options;
+ this.argOptions = options;
}
protected boolean getDefaultBoolValue()
{
return defaultBoolValue;
}
-}
+
+ private void setDescription(String d)
+ {
+ description = d;
+ }
+
+ protected String getDescription()
+ {
+ return description;
+ }
+
+ public static final String usage()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("Usage: jalview [args]");
+ sb.append(System.lineSeparator());
+
+ int maxArgLength = 0;
+ for (Arg a : EnumSet.allOf(Arg.class))
+ {
+ StringBuilder argSb = new StringBuilder();
+ argSb.append(a.hasOption(Opt.BOOLEAN) ? booleanArgString(a)
+ : a.argString());
+ if (a.hasOption(Opt.STRING))
+ argSb.append("=value");
+ if (argSb.length() > maxArgLength)
+ maxArgLength = argSb.length();
+ }
+
+ // might want to order these
+ for (Arg a : EnumSet.allOf(Arg.class))
+ {
+ StringBuilder argSb = new StringBuilder();
+ argSb.append(a.hasOption(Opt.BOOLEAN) ? booleanArgString(a)
+ : a.argString());
+ if (a.hasOption(Opt.STRING))
+ argSb.append("=value");
+ sb.append(String.format("%-" + maxArgLength + "s - %s",
+ argSb.toString(), a.getDescription()));
+ if (a.hasOption(Opt.BOOLEAN))
+ {
+ sb.append(" (default ");
+ sb.append(a.getDefaultBoolValue() ? a.argString()
+ : a.negateArgString());
+ sb.append(')');
+ }
+ sb.append(System.lineSeparator());
+ }
+ return sb.toString();
+ }
+
+ public static String booleanArgString(Arg a)
+ {
+ StringBuilder sb = new StringBuilder(a.argString());
+ if (a.hasOption(Opt.BOOLEAN))
+ {
+ sb.append('/');
+ sb.append(a.negateArgString());
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file