+ // Third param "true" uses Opt.PRIVATE args --setargile=argfile and
+ // --unsetargfile
+ return new ArgParser(argsList, initsubstitutions, true, bsa);
+ }
+
+ protected static List<String> readArgFile(File argFile)
+ {
+ List<String> args = new ArrayList<>();
+ if (argFile != null && argFile.exists())
+ {
+ try
+ {
+ for (String line : Files.readAllLines(Paths.get(argFile.getPath())))
+ {
+ if (line != null && line.length() > 0
+ && line.charAt(0) != ARGFILECOMMENT)
+ args.add(line);
+ }
+ } catch (IOException e)
+ {
+ String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath()
+ + "\": File could not be read.";
+ Console.debug(message, e);
+ Jalview.exit(message, ExitCode.FILE_NOT_READABLE);
+ }
+ }
+ return args;
+ }
+
+ // 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, Type type, ArgValues avs,
+ SubVals sv, String v, int argIndex, boolean doSubs)
+ {
+ this.argValueOperation(Op.ADDVALUE, linkedId, type, avs, sv, v, false,
+ argIndex, doSubs);
+ }
+
+ private void setBoolean(String linkedId, Type type, ArgValues avs,
+ boolean b, int argIndex)
+ {
+ 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, null, avs, null, null,
+ b, 0, false);
+ }
+
+ private void incrementCount(String linkedId, ArgValues avs)
+ {
+ this.argValueOperation(Op.INCREMENTCOUNT, linkedId, null, avs, null,
+ null, false, 0, false);
+ }
+
+ private enum Op
+ {
+ ADDVALUE, SETBOOLEAN, SETNEGATED, INCREMENTCOUNT
+ }
+
+ private void argValueOperation(Op op, String linkedId, Type type,
+ ArgValues avs, SubVals sv, String v, boolean b, int argIndex,
+ boolean doSubs)
+ {
+ // default to merge subvals if subvals are provided
+ argValueOperation(op, linkedId, type, avs, sv, true, v, b, argIndex,
+ doSubs);
+ }
+
+ /**
+ * 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.
+ *
+ * @param op
+ * The ArgParser.Op operation
+ * @param linkedId
+ * The String linkedId from the ArgValuesMap
+ * @param type
+ * The Arg.Type to attach to this ArgValue
+ * @param avs
+ * The ArgValues for this linkedId
+ * @param sv
+ * Use these SubVals on the ArgValue
+ * @param merge
+ * Merge the SubVals with any existing on the value. False will
+ * replace unless sv is null
+ * @param v
+ * The value of the ArgValue (may contain subvals).
+ * @param b
+ * The boolean value of the ArgValue.
+ * @param argIndex
+ * The argIndex for the ArgValue.
+ * @param doSubs
+ * Whether to perform substitutions on the subvals and value.
+ */
+ private void argValueOperation(Op op, String linkedId, Type type,
+ ArgValues avs, SubVals sv, boolean merge, String v, boolean b,
+ int argIndex, boolean doSubs)
+ {
+ Arg a = avs.arg();
+
+ List<String> wildcardLinkedIds = null;
+ if (a.hasOption(Opt.ALLOWMULTIID))
+ {
+ switch (linkedId)
+ {
+ case MATCHALLLINKEDIDS:
+ wildcardLinkedIds = getLinkedIds();
+ break;
+ case MATCHOPENEDLINKEDIDS:
+ wildcardLinkedIds = this.storedLinkedIds;
+ break;
+ }
+ }
+
+ // if we're not a wildcard linkedId and the arg is marked to be stored, add
+ // to storedLinkedIds
+ if (linkedId != null && wildcardLinkedIds == null
+ && a.hasOption(Opt.STORED)
+ && !storedLinkedIds.contains(linkedId))
+ {
+ storedLinkedIds.add(linkedId);
+ }
+
+ // if we are a wildcard linkedId, apply the arg and value to all appropriate
+ // linkedIds
+ if (wildcardLinkedIds != null)
+ {
+ for (String id : wildcardLinkedIds)
+ {
+ // skip incorrectly stored wildcard ids!
+ if (id == null || MATCHALLLINKEDIDS.equals(id)
+ || MATCHOPENEDLINKEDIDS.equals(id))
+ {
+ continue;
+ }
+ ArgValuesMap avm = linkedArgs.get(id);
+ // don't set an output if there isn't an input
+ if (a.hasOption(Opt.REQUIREINPUT)
+ && !avm.hasArgWithOption(Opt.INPUT))
+ continue;
+
+ ArgValues tavs = avm.getOrCreateArgValues(a);
+ switch (op)
+ {
+
+ case ADDVALUE:
+ String val = v;
+ if (sv != null)
+ {
+ if (doSubs)
+ {
+ sv = new SubVals(sv, val, merge);
+ val = makeSubstitutions(sv.getContent(), id);
+ }
+ tavs.addValue(sv, type, val, argIndex, true);
+ }
+ else
+ {
+ if (doSubs)
+ {
+ val = makeSubstitutions(v, id);
+ }
+ tavs.addValue(type, val, argIndex, true);
+ }
+ finaliseStoringArgValue(id, tavs);
+ break;
+
+ case SETBOOLEAN:
+ tavs.setBoolean(type, b, argIndex, true);
+ finaliseStoringArgValue(id, tavs);
+ break;
+
+ case SETNEGATED:
+ tavs.setNegated(b, true);
+ break;
+
+ case INCREMENTCOUNT:
+ tavs.incrementCount();
+ break;
+
+ default:
+ break;
+
+ }
+
+ }
+ }
+ else // no wildcard linkedId -- do it simpler
+ {
+ switch (op)
+ {
+ case ADDVALUE:
+ String val = v;
+ if (sv != null)
+ {
+ if (doSubs)
+ {
+ val = makeSubstitutions(v, linkedId);
+ sv = new SubVals(sv, val);
+ }
+ avs.addValue(sv, type, val, argIndex, false);
+ }
+ else
+ {
+ if (doSubs)
+ {
+ val = makeSubstitutions(v, linkedId);
+ }
+ avs.addValue(type, val, argIndex, false);
+ }
+ finaliseStoringArgValue(linkedId, avs);
+ break;
+
+ case SETBOOLEAN:
+ avs.setBoolean(type, b, argIndex, false);
+ finaliseStoringArgValue(linkedId, avs);
+ break;
+
+ case SETNEGATED:
+ avs.setNegated(b, false);
+ break;
+
+ case INCREMENTCOUNT:
+ avs.incrementCount();
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ private ArgValuesMap getOrCreateLinkedArgValuesMap(String linkedId)
+ {
+ if (linkedArgs.containsKey(linkedId)
+ && linkedArgs.get(linkedId) != null)
+ return linkedArgs.get(linkedId);
+
+ linkedArgs.put(linkedId, new ArgValuesMap(linkedId));
+ return linkedArgs.get(linkedId);
+ }
+
+ public boolean isOldStyle()
+ {
+ return oldArguments;
+ }
+
+ public boolean isMixedStyle()
+ {
+ return mixedArguments;
+ }
+
+ public String[] getMixedExamples()
+ {
+ return mixedExamples;