From: Ben Soares Date: Tue, 4 Apr 2023 19:45:08 +0000 (+0100) Subject: JAL-629 more info in usage statement X-Git-Tag: Release_2_11_4_0~405 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d7a4a1a91d850ed8c246c0e69edf1e2dd760b49c;p=jalview.git JAL-629 more info in usage statement --- diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index 65a865b..e22cfc6 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -1,5 +1,6 @@ package jalview.bin.argparser; +import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; import java.util.List; @@ -227,6 +228,17 @@ public enum Arg return description; } + 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(); + } + public static final String usage() { StringBuilder sb = new StringBuilder(); @@ -237,6 +249,8 @@ public enum Arg int maxArgLength = 0; for (Arg a : EnumSet.allOf(Arg.class)) { + if (a.hasOption(Opt.PRIVATE)) + continue; StringBuilder argSb = new StringBuilder(); argSb.append(a.hasOption(Opt.BOOLEAN) ? booleanArgString(a) : a.argString()); @@ -246,9 +260,11 @@ public enum Arg maxArgLength = argSb.length(); } - // might want to order these + // might want to sort these for (Arg a : EnumSet.allOf(Arg.class)) { + if (a.hasOption(Opt.PRIVATE)) + continue; StringBuilder argSb = new StringBuilder(); argSb.append(a.hasOption(Opt.BOOLEAN) ? booleanArgString(a) : a.argString()); @@ -256,26 +272,43 @@ public enum Arg argSb.append("=value"); sb.append(String.format("%-" + maxArgLength + "s - %s", argSb.toString(), a.getDescription())); + + List options = new ArrayList<>(); + if (a.hasOption(Opt.BOOLEAN)) { - sb.append(" (default "); - sb.append(a.getDefaultBoolValue() ? a.argString() - : a.negateArgString()); + options.add("default " + (a.getDefaultBoolValue() ? a.argString() + : a.negateArgString())); + } + + if (a.hasOption(Opt.MULTI)) + { + options.add("multiple"); + } + + if (a.hasOption(Opt.LINKED)) + { + options.add("can be linked"); + } + + if (a.hasOption(Opt.GLOB)) + { + options.add("allows file globs"); + } + + if (a.hasOption(Opt.ALLOWSUBSTITUTIONS)) + { + options.add("allows substitutions"); + } + + if (options.size() > 0) + { + sb.append(" ("); + sb.append(String.join("; ", options)); 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