From: Ben Soares Date: Thu, 18 May 2023 16:16:42 +0000 (+0100) Subject: JAL-629 fixes to typed args X-Git-Tag: Release_2_11_4_0~316 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=45502494dee1b9f2d7a5a1d62dc00ed24acfc6f4;p=jalview.git JAL-629 fixes to typed args --- diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 8bc3e1b..3d20d3c 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -494,9 +494,8 @@ public class Jalview { if (bootstrapArgs.containsType(Type.HELP)) { - System.out.println("##### HERE"); - System.out - .println(Arg.usage(bootstrapArgs.getArgsOfType(Type.HELP))); + List helpArgs = bootstrapArgs.getArgsOfType(Type.HELP); + System.out.println(Arg.usage(helpArgs)); Jalview.exit(null, 0); } if (aparser.contains("help") || aparser.contains("h")) diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index a7fc0f7..a9cacbd 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -18,7 +18,7 @@ public enum Arg // Initialising arguments (BOOTSTRAP) HELP(Type.HELP, "h", "Display this help statement", Opt.UNARY, - Opt.BOOTSTRAP, Opt.HASTYPE), + Opt.BOOTSTRAP, Opt.HASTYPE, Opt.MULTI), /* * Other --help-type Args will be added by the static block. */ @@ -319,8 +319,10 @@ public enum Arg OUTPUT("Arguments used to save data from a processed alignment"), IMAGE("Arguments used to export an image of an alignment"), FLOW("Arguments that control processing of the other arguments"), + HELP("Arguments to provide help text"), // --help ALL("All arguments"), // mostly just a place-holder for --help-all - HELP("Arguments to provide help text"); + NONE("No specific arguments"), // mostly a place-holder for --help + INVALID("This type of argument doesn't exist"); private String description; diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index 4e1793d..6d1251c 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -283,9 +283,15 @@ public class ArgParser Arg potentialArg = argMap.get(potentialArgName); if (potentialArg != null && potentialArg.hasOption(Opt.HASTYPE)) { - argName = argName.substring(0, dashPos); String typeName = argName.substring(dashPos + 1); - type = Type.valueOf(typeName); + try + { + type = Type.valueOf(typeName); + } catch (IllegalArgumentException e) + { + type = Type.INVALID; + } + argName = argName.substring(0, dashPos); } } diff --git a/src/jalview/bin/argparser/BootstrapArgs.java b/src/jalview/bin/argparser/BootstrapArgs.java index 1c54355..faa4a43 100644 --- a/src/jalview/bin/argparser/BootstrapArgs.java +++ b/src/jalview/bin/argparser/BootstrapArgs.java @@ -7,6 +7,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -64,46 +65,50 @@ public class BootstrapArgs String val = null; Type type = null; // remove "--" - arg = arg.substring(ArgParser.DOUBLEDASH.length()); + argName = arg.substring(ArgParser.DOUBLEDASH.length()); // look for equals e.g. --arg=value - int equalPos = arg.indexOf(ArgParser.EQUALS); - if (equalPos > -1 - && ArgParser.argMap.containsKey(arg.substring(0, equalPos))) + int equalPos = argName.indexOf(ArgParser.EQUALS); + if (equalPos > -1) { - argName = arg.substring(0, equalPos); - val = arg.substring(equalPos + 1); + val = argName.substring(equalPos + 1); + argName = argName.substring(0, equalPos); } + // check for boolean prepended by "no" - else if (arg.startsWith(ArgParser.NEGATESTRING) + if (argName.startsWith(ArgParser.NEGATESTRING) && ArgParser.argMap.containsKey( - arg.substring(ArgParser.NEGATESTRING.length()))) + argName.substring(ArgParser.NEGATESTRING.length()))) { - argName = arg.substring(ArgParser.NEGATESTRING.length()); val = "false"; + argName = argName.substring(ArgParser.NEGATESTRING.length()); } - else if (ArgParser.argMap.containsKey(arg)) - { - argName = arg; - val = "true"; - } - else + + // look for type modification e.g. --help-opening + int dashPos = argName.indexOf(ArgParser.SINGLEDASH); + if (dashPos > -1) { - // look for type modification e.g. --help-opening - int dashPos = arg.indexOf(ArgParser.SINGLEDASH); - if (dashPos > -1) + String potentialArgName = argName.substring(0, dashPos); + Arg potentialArg = ArgParser.argMap.get(potentialArgName); + if (potentialArg != null && potentialArg.hasOption(Opt.HASTYPE)) { - String potentialArgName = arg.substring(0, dashPos); - Arg potentialArg = ArgParser.argMap.get(potentialArgName); - if (potentialArg != null && potentialArg.hasOption(Opt.HASTYPE)) + String typeName = argName.substring(dashPos + 1); + try { - argName = arg.substring(0, dashPos); - String typeName = arg.substring(dashPos + 1); - type = Type.valueOf(typeName); + type = Type.valueOf(typeName.toUpperCase(Locale.ROOT)); + } catch (IllegalArgumentException e) + { + type = Type.INVALID; } + argName = argName.substring(0, dashPos); } } + if (ArgParser.argMap.containsKey(argName) && val == null) + { + val = "true"; + } + Arg a = ArgParser.argMap.get(argName); if (a == null || !a.hasOption(Opt.BOOTSTRAP))