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 = '=';
// --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
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(
openEachInitialFilenames = false;
}
- String argName = null;
- String val = null;
- List<String> 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<String> 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)
{
{
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))
+ {
+ argName = argName.substring(0, dashPos);
+ String typeName = argName.substring(dashPos + 1);
+ type = Type.valueOf(typeName);
+ }
+ }
+
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())))
}
String autoCounterString = null;
- boolean usingAutoCounterLinkedId = false;
String defaultLinkedId = defaultLinkedId(false);
boolean usingDefaultLinkedId = false;
if (a.hasOption(Opt.LINKED))
autoCounterString = Integer.toString(linkedIdAutoCounter);
linkedId = linkedId.replace(LINKEDIDAUTOCOUNTER,
autoCounterString);
- usingAutoCounterLinkedId = true;
Console.debug(
"Changing linkedId to '" + linkedId + "' from " + arg);
}
autoCounterString = Integer.toString(++linkedIdAutoCounter);
linkedId = linkedId.replace(INCREMENTLINKEDIDAUTOCOUNTER,
autoCounterString);
- usingAutoCounterLinkedId = true;
Console.debug(
"Changing linkedId to '" + linkedId + "' from " + arg);
}
{
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
}
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
// 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
// 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();
val = makeSubstitutions(v, id);
sv = new SubVals(sv, val);
}
- tavs.addValue(sv, val, argIndex, true);
+ tavs.addValue(sv, type, val, argIndex, true);
}
else
{
{
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;
val = makeSubstitutions(v, linkedId);
sv = new SubVals(sv, val);
}
- avs.addValue(sv, val, argIndex, false);
+ avs.addValue(sv, type, val, argIndex, false);
}
else
{
{
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;