X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2Fargparser%2FArgParser.java;h=6d1251ce97bc1adf581676f7d9f691b992a7a79c;hb=b382fe5af3f138ede6db2ab1efc05ddd0819eea6;hp=e6bd9176aefd32fab099e8986afb0f43b3ae6d89;hpb=167f4222520be1ec49277dab1e5350d236ed6292;p=jalview.git diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index e6bd917..6d1251c 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -38,11 +38,14 @@ import jalview.bin.Cache; import jalview.bin.Console; import jalview.bin.Jalview; import jalview.bin.argparser.Arg.Opt; +import jalview.bin.argparser.Arg.Type; import jalview.util.FileUtils; import jalview.util.HttpUtils; public class ArgParser { + protected static final String SINGLEDASH = "-"; + protected static final String DOUBLEDASH = "--"; protected static final char EQUALS = '='; @@ -105,10 +108,6 @@ public class ArgParser // --argfile name private static final String ARGFILEDIRNAME = "{argfiledirname}"; - // an output file wildcard to signify --output=*.ext is really --all --output - // {basename}.ext - private static final String OUTPUTWILDCARD = "*."; - // flag to say whether {n} subtitutions in output filenames should be made. // Turn on and off with --substitutions and --nosubstitutions // Start with it on @@ -148,8 +147,7 @@ public class ArgParser if (argMap.containsKey(argName)) { Console.warn("Trying to add argument name multiple times: '" - + argName + "'"); // RESTORE THIS WHEN - // MERGED + + argName + "'"); if (argMap.get(argName) != a) { Console.error( @@ -246,13 +244,17 @@ public class ArgParser openEachInitialFilenames = false; } - String argName = null; - String val = null; - List globVals = null; // for Opt.GLOB only - SubVals globSubVals = null; // also for use by Opt.GLOB only - String linkedId = null; + // look for double-dash, e.g. --arg if (arg.startsWith(DOUBLEDASH)) { + String argName = null; + String val = null; + List globVals = null; // for Opt.GLOB only + SubVals globSubVals = null; // also for use by Opt.GLOB only + String linkedId = null; + Type type = null; + + // look for equals e.g. --arg=value int equalPos = arg.indexOf(EQUALS); if (equalPos > -1) { @@ -263,17 +265,38 @@ public class ArgParser { argName = arg.substring(DOUBLEDASH.length()); } + + // look for linked ID e.g. --arg[linkedID] int idOpen = argName.indexOf('['); int idClose = argName.indexOf(']'); - if (idOpen > -1 && idClose == argName.length() - 1) { linkedId = argName.substring(idOpen + 1, idClose); argName = argName.substring(0, idOpen); } + // look for type modification e.g. --help-opening + int dashPos = argName.indexOf(SINGLEDASH); + if (dashPos > -1) + { + String potentialArgName = argName.substring(0, dashPos); + Arg potentialArg = argMap.get(potentialArgName); + if (potentialArg != null && potentialArg.hasOption(Opt.HASTYPE)) + { + String typeName = argName.substring(dashPos + 1); + try + { + type = Type.valueOf(typeName); + } catch (IllegalArgumentException e) + { + type = Type.INVALID; + } + argName = argName.substring(0, dashPos); + } + } + Arg a = argMap.get(argName); - // check for boolean prepended by "no" + // check for boolean prepended by "no" e.g. --nowrap boolean negated = false; if (a == null && argName.startsWith(NEGATESTRING) && argMap .containsKey(argName.substring(NEGATESTRING.length()))) @@ -416,7 +439,6 @@ public class ArgParser } String autoCounterString = null; - boolean usingAutoCounterLinkedId = false; String defaultLinkedId = defaultLinkedId(false); boolean usingDefaultLinkedId = false; if (a.hasOption(Opt.LINKED)) @@ -469,7 +491,6 @@ public class ArgParser autoCounterString = Integer.toString(linkedIdAutoCounter); linkedId = linkedId.replace(LINKEDIDAUTOCOUNTER, autoCounterString); - usingAutoCounterLinkedId = true; Console.debug( "Changing linkedId to '" + linkedId + "' from " + arg); } @@ -479,7 +500,6 @@ public class ArgParser autoCounterString = Integer.toString(++linkedIdAutoCounter); linkedId = linkedId.replace(INCREMENTLINKEDIDAUTOCOUNTER, autoCounterString); - usingAutoCounterLinkedId = true; Console.debug( "Changing linkedId to '" + linkedId + "' from " + arg); } @@ -527,7 +547,7 @@ public class ArgParser { String v = gve.nextElement(); SubVals vsv = new SubVals(globSubVals, v); - addValue(linkedId, avs, vsv, v, argIndex++, true); + addValue(linkedId, type, avs, vsv, v, argIndex++, true); // if we're using defaultLinkedId and the arg increments the // counter: if (gve.hasMoreElements() && usingDefaultLinkedId @@ -543,17 +563,17 @@ public class ArgParser } else { - addValue(linkedId, avs, val, argIndex, true); + addValue(linkedId, type, avs, val, argIndex, true); } } else if (a.hasOption(Opt.BOOLEAN)) { - setBoolean(linkedId, avs, !negated, argIndex); + setBoolean(linkedId, type, avs, !negated, argIndex); setNegated(linkedId, avs, negated); } else if (a.hasOption(Opt.UNARY)) { - setBoolean(linkedId, avs, true, argIndex); + setBoolean(linkedId, type, avs, true, argIndex); } // remove the '*' or 'open*' linkedId that should be empty if it was @@ -981,37 +1001,37 @@ public class ArgParser // the following methods look for the "*" linkedId and add the argvalue to all // linkedId ArgValues if it does. // This version inserts the subvals sv into all created values - private void addValue(String linkedId, ArgValues avs, SubVals sv, - String v, int argIndex, boolean doSubs) + private void addValue(String linkedId, Type type, ArgValues avs, + SubVals sv, String v, int argIndex, boolean doSubs) { - this.argValueOperation(Op.ADDVALUE, linkedId, avs, sv, v, false, + this.argValueOperation(Op.ADDVALUE, linkedId, type, avs, sv, v, false, argIndex, doSubs); } - private void addValue(String linkedId, ArgValues avs, String v, + private void addValue(String linkedId, Type type, ArgValues avs, String v, int argIndex, boolean doSubs) { - this.argValueOperation(Op.ADDVALUE, linkedId, avs, null, v, false, + this.argValueOperation(Op.ADDVALUE, linkedId, type, avs, null, v, false, argIndex, doSubs); } - private void setBoolean(String linkedId, ArgValues avs, boolean b, - int argIndex) + private void setBoolean(String linkedId, Type type, ArgValues avs, + boolean b, int argIndex) { - this.argValueOperation(Op.SETBOOLEAN, linkedId, avs, null, null, b, - argIndex, false); + this.argValueOperation(Op.SETBOOLEAN, linkedId, type, avs, null, null, + b, argIndex, false); } private void setNegated(String linkedId, ArgValues avs, boolean b) { - this.argValueOperation(Op.SETNEGATED, linkedId, avs, null, null, b, 0, - false); + this.argValueOperation(Op.SETNEGATED, linkedId, null, avs, null, null, + b, 0, false); } private void incrementCount(String linkedId, ArgValues avs) { - this.argValueOperation(Op.INCREMENTCOUNT, linkedId, avs, null, null, - false, 0, false); + this.argValueOperation(Op.INCREMENTCOUNT, linkedId, null, avs, null, + null, false, 0, false); } private enum Op @@ -1022,8 +1042,9 @@ public class ArgParser // The following operations look for the "*" and "open*" linkedIds and add the // argvalue to all appropriate linkedId ArgValues if it does. // If subvals are supplied, they are inserted into all new set values. - private void argValueOperation(Op op, String linkedId, ArgValues avs, - SubVals sv, String v, boolean b, int argIndex, boolean doSubs) + private void argValueOperation(Op op, String linkedId, Type type, + ArgValues avs, SubVals sv, String v, boolean b, int argIndex, + boolean doSubs) { Arg a = avs.arg(); @@ -1079,7 +1100,7 @@ public class ArgParser val = makeSubstitutions(v, id); sv = new SubVals(sv, val); } - tavs.addValue(sv, val, argIndex, true); + tavs.addValue(sv, type, val, argIndex, true); } else { @@ -1087,13 +1108,13 @@ public class ArgParser { val = makeSubstitutions(v, id); } - tavs.addValue(val, argIndex, true); + tavs.addValue(type, val, argIndex, true); } finaliseStoringArgValue(id, tavs); break; case SETBOOLEAN: - tavs.setBoolean(b, argIndex, true); + tavs.setBoolean(type, b, argIndex, true); finaliseStoringArgValue(id, tavs); break; @@ -1125,7 +1146,7 @@ public class ArgParser val = makeSubstitutions(v, linkedId); sv = new SubVals(sv, val); } - avs.addValue(sv, val, argIndex, false); + avs.addValue(sv, type, val, argIndex, false); } else { @@ -1133,13 +1154,13 @@ public class ArgParser { val = makeSubstitutions(v, linkedId); } - avs.addValue(val, argIndex, false); + avs.addValue(type, val, argIndex, false); } finaliseStoringArgValue(linkedId, avs); break; case SETBOOLEAN: - avs.setBoolean(b, argIndex, false); + avs.setBoolean(type, b, argIndex, false); finaliseStoringArgValue(linkedId, avs); break;