*/
package jalview.bin;
+import java.io.File;
+import java.io.IOException;
import java.net.URLDecoder;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
private static enum Opt
{
- BOOLEAN, STRING, UNARY, MULTI, LINKED, ORDERED, NODUPLICATEVALUES
+ BOOLEAN, STRING, UNARY, MULTI, LINKED, NODUPLICATEVALUES
}
+ // These bootstrap args are simply parsed before a full parse of arguments and
+ // so are accessible at an earlier stage to (e.g.) set debug log leve, provide
+ // a props file (that might set log level), run headlessly, read an argfile
+ // instead of other args.
+ private static final Collection<Arg> bootstrapArgs = new ArrayList(
+ Arrays.asList(Arg.PROPS, Arg.DEBUG, Arg.HEADLESS, Arg.ARGFILE));
+
public enum Arg
{
/*
USAGESTATS, OPEN, OPEN2, PROPS, QUESTIONNAIRE, SETPROP, TREE, VDOC,
VSESS, OUTPUT, OUTPUTTYPE, SSANNOTATION, NOTEMPFAC, TEMPFAC,
TEMPFAC_LABEL, TEMPFAC_DESC, TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP,
- NOSTRUCTURE, STRUCTURE, IMAGE, QUIT, DEBUG("d");
+ NOSTRUCTURE, STRUCTURE, IMAGE, QUIT, DEBUG("d"), ARGFILE;
static
{
IMAGE.setOptions(Opt.STRING, Opt.LINKED);
QUIT.setOptions(Opt.UNARY);
DEBUG.setOptions(Opt.BOOLEAN);
+ ARGFILE.setOptions(Opt.STRING);
}
private final String[] argNames;
public void parseVals(String item)
{
+ if (item == null)
+ return;
if (item.indexOf('[') == 0 && item.indexOf(']') > 1)
{
int openBracket = item.indexOf('[');
{
if (m == null || !m.containsKey(a))
return false;
- return getArgValue(a) != null;
+ return a.hasOption(Opt.STRING) ? getArgValue(a) != null
+ : this.getBoolean(a);
}
protected boolean hasValue(Arg a, String val)
}
}
- private static final Collection<Arg> bootstrapArgs = new ArrayList(
- Arrays.asList(Arg.PROPS, Arg.DEBUG));
-
public static Map<Arg, String> bootstrapArgs(String[] args)
{
Map<Arg, String> bootstrapArgMap = new HashMap<>();
}
return bootstrapArgMap;
}
+
+ public static ArgParser parseArgFile(String argFilename)
+ {
+ List<String> argsList = null;
+ File argFile = new File(argFilename);
+ if (!argFile.exists())
+ {
+ System.err.println("--" + Arg.ARGFILE.name().toLowerCase(Locale.ROOT)
+ + "=\"" + argFilename + "\": File does not exist.");
+ System.exit(2);
+ }
+ try
+ {
+ argsList = Files.readAllLines(Paths.get(argFilename));
+ } catch (IOException e)
+ {
+ System.err.println("--" + Arg.ARGFILE.name().toLowerCase(Locale.ROOT)
+ + "=\"" + argFilename + "\": File could not be read.");
+ System.exit(3);
+ }
+ return new ArgParser((String[]) argsList.toArray());
+ }
}
\ No newline at end of file
private Map<String, AlignFrame> afMap;
+ private static boolean commandArgsProvided = false;
+
+ public static boolean commandArgsProvided()
+ {
+ return commandArgsProvided;
+ }
+
public static boolean processArgs(ArgParser ap, boolean h)
{
argParser = ap;
*/
if (avm.containsArg(Arg.OPEN))
{
+ commandArgsProvided = true;
long progress = -1;
boolean first = true;
+ boolean progressBarSet = false;
AlignFrame af;
for (ArgValue av : avm.getArgValueList(Arg.OPEN))
{
MessageManager.getString(
"status.processing_commandline_args"),
progress = System.currentTimeMillis());
+ progressBarSet = true;
}
}
else
{
Console.warn("No more files to open");
- if (desktop != null)
- desktop.setProgressBar(null, progress);
}
}
+ if (progressBarSet && desktop != null)
+ desktop.setProgressBar(null, progress);
}
AlignFrame af = afMap.get(id);
if (avm.containsArg(Arg.STRUCTURE))
{
+ commandArgsProvided = true;
for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
{
String val = av.getValue();
}
// new ArgParser
- ArgParser argparser = new ArgParser(args);
+ ArgParser argparser;
+ // --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS
+ if (bootstrapArgs.containsKey(Arg.ARGFILE))
+ {
+ argparser = ArgParser.parseArgFile(bootstrapArgs.get(Arg.ARGFILE));
+ }
+ else
+ {
+ argparser = new ArgParser(args);
+ }
if (!Platform.isJS())
/**
}
}
// Run Commands from cli
- boolean commandsSuccess = Commands.processArgs(argparser, headless);
+ boolean commandsSuccess = Commands.processArgs(argparser, headlessArg);
if (commandsSuccess)
{
Console.info("Successfully completed commands");
// ////////////////////
if (!Platform.isJS() && !headless && file == null
- && Cache.getDefault("SHOW_STARTUP_FILE", true))
+ && Cache.getDefault("SHOW_STARTUP_FILE", true)
+ && !Commands.commandArgsProvided())
+ // don't open the startup file if command line args have been processed
+ // (&& !Commands.commandArgsProvided())
/**
* Java only
*