From 4fd4608b88401dbb1a86a29f8d607c7481145e27 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Sat, 27 May 2023 19:46:33 +0100 Subject: [PATCH] JAL-4121 Store Arg.Opts in bootstrapArgs. Change Opt.OUTPUT to Opt.OUTPUTFILE for clarity. isHeadless() method sets policy for headless mode including assumption of headless if there's an Opt.OUTPUTFILE Arg. --- src/jalview/bin/Jalview.java | 30 ++++++++++++++++++++++---- src/jalview/bin/argparser/Arg.java | 22 +++++++++++++------ src/jalview/bin/argparser/ArgParser.java | 4 ++-- src/jalview/bin/argparser/BootstrapArgs.java | 22 +++++++++++++++++++ 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 8fa4ac7..159cf75 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -532,17 +532,17 @@ public class Jalview Jalview.exit(null, 0); } - if (bootstrapArgs.contains(Arg.HEADLESS)) + // new CLI + headlessArg = isHeadless(bootstrapArgs); + if (headlessArg) { System.setProperty("java.awt.headless", "true"); - // new - headlessArg = bootstrapArgs.getBoolean(Arg.HEADLESS); } + // old CLI if (aparser.contains("nodisplay") || aparser.contains("nogui") || aparser.contains("headless")) { System.setProperty("java.awt.headless", "true"); - // old headless = true; } // anything else! @@ -1883,4 +1883,26 @@ public class Jalview System.out.println("[TESTOUTPUT] arg " + (yes ? a.argString() : a.negateArgString()) + " was set"); } + + private static boolean isHeadless(BootstrapArgs bootstrapArgs) + { + if (bootstrapArgs == null) + { + return false; + } + boolean isHeadless = false; + if (bootstrapArgs.contains(Arg.GUI)) + { + isHeadless = !bootstrapArgs.getBoolean(Arg.GUI); + } + else if (bootstrapArgs.contains(Arg.HEADLESS)) + { + isHeadless = bootstrapArgs.getBoolean(Arg.HEADLESS); + } + else if (bootstrapArgs.argsHaveOption(Opt.OUTPUTFILE)) + { + isHeadless = true; + } + return isHeadless; + } } diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index 8bac623..c502eec 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -28,7 +28,11 @@ public enum Arg + ChannelProperties.getProperty("app_name"), Opt.UNARY, Opt.BOOTSTRAP), HEADLESS(Type.CONFIG, - "Run Jalview in headless mode. No GUI interface will be created and Jalview will quit after all arguments have been processed.", + "Run Jalview in headless mode. No GUI interface will be created and Jalview will quit after all arguments have been processed. " + + "Headless mode is assumed if an output file is to be generated, this can be overridden with --noheadless or --gui.", + Opt.BOOLEAN, Opt.BOOTSTRAP), + GUI(Type.CONFIG, + "Do not run Jalview in headless mode. This overrides the assumption of headless mode when an output file is to be generated.", Opt.UNARY, Opt.BOOTSTRAP), JABAWS(Type.CONFIG, "Set a different URL to connect to a JABAWS server.", Opt.STRING, Opt.BOOTSTRAP), @@ -140,7 +144,7 @@ public enum Arg "Output an image of the open alignment window. Format is specified by the subval modifier, a following --type argument or guessed from the file extension. Valid formats/extensions are:\n" + "svg,\n" + "png,\n" + "eps,\n" + "html,\n" + "biojs.", Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS, Opt.ALLOWALL, - Opt.REQUIREINPUT, Opt.OUTPUT, Opt.PRIMARY), + Opt.REQUIREINPUT, Opt.OUTPUTFILE, Opt.PRIMARY), TYPE(Type.IMAGE, "Set the image format for the preceding --image. Valid values are:\n" + "svg,\n" + "png,\n" + "eps,\n" + "html,\n" + "biojs.", @@ -160,7 +164,7 @@ public enum Arg Opt.STRING, Opt.LINKED, Opt.ALLOWALL), STRUCTUREIMAGE(Type.STRUCTUREIMAGE, "Export an image of a 3D structure opened in JMOL", Opt.STRING, - Opt.LINKED, Opt.MULTI), + Opt.LINKED, Opt.MULTI, Opt.OUTPUTFILE), STRUCTUREIMAGETYPE(Type.STRUCTUREIMAGE, "Set the structure image format for the preceding --structureimage. Valid values are:\n" + "svg,\n" + "png,\n" + "eps,\n" + "html,\n" + "biojs.", @@ -188,7 +192,7 @@ public enum Arg + "clustal (aln),\n" + "phylip (phy),\n" + "jalview (jvp, jar).", Opt.STRING, Opt.LINKED, Opt.ALLOWSUBSTITUTIONS, Opt.ALLOWALL, - Opt.REQUIREINPUT, Opt.OUTPUT, Opt.PRIMARY), + Opt.REQUIREINPUT, Opt.OUTPUTFILE, Opt.PRIMARY), FORMAT(Type.OUTPUT, "Sets the format for the preceding --output file. Valid formats are:\n" + "fasta,\n" + "pfam,\n" + "stockholm,\n" + "pir,\n" @@ -325,8 +329,9 @@ public enum Arg INPUT, // This Arg counts as an input for REQUIREINPUT REQUIREINPUT, // This Arg can only be applied via --all if there is an // input (i.e. --open or --append) - OUTPUT, // This Arg provides an output filename. With Opt.ALLOWALL *.ext is - // shorthand for --all --output={basename}.ext + OUTPUTFILE, // This Arg provides an output filename. With Opt.ALLOWALL *.ext + // is + // shorthand for --all --output={basename}.ext STORED, // This Arg resets and creates a new set of "opened" linkedIds HELP, // This Arg is a --help type arg PRIMARY, // This Arg is the main Arg for its type @@ -489,6 +494,11 @@ public enum Arg return true; } + protected Opt[] getOptions() + { + return argOptions; + } + protected void setOptions(Opt... options) { this.argOptions = options; diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index 0a8b8d3..f08e678 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -453,7 +453,7 @@ public class ArgParser { if (linkedId == null) { - if (a.hasOption(Opt.OUTPUT) && a.hasOption(Opt.ALLOWALL) + if (a.hasOption(Opt.OUTPUTFILE) && a.hasOption(Opt.ALLOWALL) && val.startsWith(MATCHALLLINKEDIDS)) { // --output=*.ext is shorthand for --all --output {basename}.ext @@ -464,7 +464,7 @@ public class ArgParser val = LINKEDIDDIRNAME + File.separator + LINKEDIDBASENAME + val.substring(MATCHALLLINKEDIDS.length()); } - else if (a.hasOption(Opt.OUTPUT) && a.hasOption(Opt.ALLOWALL) + else if (a.hasOption(Opt.OUTPUTFILE) && a.hasOption(Opt.ALLOWALL) && val.startsWith(MATCHOPENEDLINKEDIDS)) { // --output=open*.ext is shorthand for --opened --output diff --git a/src/jalview/bin/argparser/BootstrapArgs.java b/src/jalview/bin/argparser/BootstrapArgs.java index faa4a43..a6bad24 100644 --- a/src/jalview/bin/argparser/BootstrapArgs.java +++ b/src/jalview/bin/argparser/BootstrapArgs.java @@ -23,6 +23,8 @@ public class BootstrapArgs private Set argFiles = new HashSet<>(); + private Set argsOptions = new HashSet<>(); + public static BootstrapArgs getBootstrapArgs(String[] args) { List argList = new ArrayList<>(Arrays.asList(args)); @@ -111,6 +113,17 @@ public class BootstrapArgs Arg a = ArgParser.argMap.get(argName); + if (a != null) + { + for (Opt opt : a.getOptions()) + { + if (!argsOptions.contains(opt)) + { + argsOptions.add(opt); + } + } + } + if (a == null || !a.hasOption(Opt.BOOTSTRAP)) { // not a valid bootstrap arg @@ -284,8 +297,17 @@ public class BootstrapArgs return false; } if (bootstrapArgMap.containsKey(a)) + { return Boolean.parseBoolean(get(a)); + } else + { return a.getDefaultBoolValue(); + } + } + + public boolean argsHaveOption(Opt opt) + { + return argsOptions.contains(opt); } } -- 1.7.10.2