From dd27b3a58a81bcf699d547822d37aec77eb00e7e Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Sun, 12 Mar 2023 01:13:59 +0000 Subject: [PATCH] JAL-629 Allow substitutions of {} = defaultCounter, {n} = autoCounter, {++n} = incremented autoCounter on args involving an output filename. --- src/jalview/bin/ArgParser.java | 65 ++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/src/jalview/bin/ArgParser.java b/src/jalview/bin/ArgParser.java index dfd3457..14785ea 100644 --- a/src/jalview/bin/ArgParser.java +++ b/src/jalview/bin/ArgParser.java @@ -64,7 +64,7 @@ public class ArgParser private static enum Opt { BOOLEAN, STRING, UNARY, MULTI, LINKED, NODUPLICATEVALUES, BOOTSTRAP, - GLOB, NOACTION + GLOB, NOACTION, ALLOWSUBSTITUTIONS } public enum Arg @@ -95,13 +95,15 @@ public class ArgParser SHOWOVERVIEW.setOptions(Opt.UNARY, Opt.LINKED); ANNOTATIONS.setOptions(Opt.STRING, Opt.LINKED); COLOUR.setOptions(Opt.STRING, Opt.LINKED); - FEATURES.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI); - GROOVY.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI); + FEATURES.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, + Opt.ALLOWSUBSTITUTIONS); + GROOVY.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, + Opt.ALLOWSUBSTITUTIONS); GROUPS.setOptions(Opt.STRING, Opt.LINKED); HEADLESS.setOptions(Opt.UNARY, Opt.BOOTSTRAP); JABAWS.setOptions(Opt.STRING); - ANNOTATION.setOptions(true, Opt.BOOLEAN); - ANNOTATION2.setOptions(true, Opt.BOOLEAN); + ANNOTATION.setOptions(true, Opt.BOOLEAN, Opt.LINKED); + ANNOTATION2.setOptions(true, Opt.BOOLEAN, Opt.LINKED); DISPLAY.setOptions(true, Opt.BOOLEAN); GUI.setOptions(true, Opt.BOOLEAN); NEWS.setOptions(true, Opt.BOOLEAN); @@ -109,8 +111,9 @@ public class ArgParser // expects a string value SORTBYTREE.setOptions(true, Opt.BOOLEAN); USAGESTATS.setOptions(true, Opt.BOOLEAN); - OPEN.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.GLOB); - OPEN2.setOptions(Opt.STRING, Opt.LINKED); + OPEN.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, Opt.GLOB, + Opt.ALLOWSUBSTITUTIONS); + OPEN2.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS); PROPS.setOptions(Opt.STRING, Opt.BOOTSTRAP); QUESTIONNAIRE.setOptions(Opt.STRING); SETPROP.setOptions(Opt.STRING); @@ -119,7 +122,7 @@ public class ArgParser VDOC.setOptions(Opt.UNARY); VSESS.setOptions(Opt.UNARY); - OUTPUT.setOptions(Opt.STRING, Opt.LINKED); + OUTPUT.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS); OUTPUTTYPE.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI); SSANNOTATION.setOptions(Opt.BOOLEAN, Opt.LINKED); @@ -129,16 +132,19 @@ public class ArgParser TEMPFAC_DESC.setOptions(Opt.STRING, Opt.LINKED); TEMPFAC_SHADING.setOptions(Opt.BOOLEAN, Opt.LINKED); TITLE.setOptions(Opt.STRING, Opt.LINKED); - PAEMATRIX.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI); + PAEMATRIX.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, + Opt.ALLOWSUBSTITUTIONS); NOSTRUCTURE.setOptions(Opt.UNARY, Opt.LINKED); - STRUCTURE.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI); + STRUCTURE.setOptions(Opt.STRING, Opt.LINKED, Opt.MULTI, + Opt.ALLOWSUBSTITUTIONS); WRAP.setOptions(Opt.BOOLEAN, Opt.LINKED); - IMAGE.setOptions(Opt.STRING, Opt.LINKED); + IMAGE.setOptions(Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS); QUIT.setOptions(Opt.UNARY); CLOSE.setOptions(Opt.UNARY, Opt.LINKED); DEBUG.setOptions(Opt.BOOLEAN, Opt.BOOTSTRAP); QUIET.setOptions(Opt.UNARY, Opt.MULTI, Opt.BOOTSTRAP); - ARGFILE.setOptions(Opt.STRING, Opt.MULTI, Opt.BOOTSTRAP, Opt.GLOB); + ARGFILE.setOptions(Opt.STRING, Opt.MULTI, Opt.BOOTSTRAP, Opt.GLOB, + Opt.ALLOWSUBSTITUTIONS); INCREMENT.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION); NPP.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION); SUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.MULTI, Opt.NOACTION); @@ -679,11 +685,13 @@ public class ArgParser if (a.hasOption(Opt.GLOB) && vals != null && vals.size() > 0) { for (String v : vals) - avs.addValue(val, argIndex++); + { + avs.addValue(makeSubstitutions(v), argIndex++); + } } else { - avs.addValue(val, argIndex); + avs.addValue(makeSubstitutions(val), argIndex); } } else if (a.hasOption(Opt.BOOLEAN)) @@ -719,6 +727,33 @@ public class ArgParser } } + private String makeSubstitutions(String val) + { + if (!this.substitutions) + return val; + + String subvals; + String rest; + if (val.indexOf('[') == 0 && val.indexOf(']') > 1) + { + int closeBracket = val.indexOf(']'); + if (val.length() == closeBracket) + return val; + subvals = val.substring(0, closeBracket + 1); + rest = val.substring(closeBracket + 1); + } + else + { + subvals = ""; + rest = val; + } + rest.replace(AUTOCOUNTERLINKEDID, String.valueOf(idCounter)); + rest.replace(INCREMENTAUTOCOUNTERLINKEDID, String.valueOf(++idCounter)); + rest.replace("{}", String.valueOf(defaultLinkedIdCounter)); + + return new StringBuilder(subvals).append(rest).toString(); + } + /* * A helper method to take a list of String args where we're expecting * {"--previousargs", "--arg", "file1", "file2", "file3", "--otheroptionsornot"} @@ -891,7 +926,7 @@ public class ArgParser return; if (item.indexOf('[') == 0 && item.indexOf(']') > 1) { - int openBracket = item.indexOf('['); + int openBracket = 0; int closeBracket = item.indexOf(']'); String subvalsString = item.substring(openBracket + 1, closeBracket); -- 1.7.10.2