// --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS
if (bootstrapArgs.contains(Arg.ARGFILE))
{
- argparser = ArgParser
- .parseArgFiles(bootstrapArgs.getList(Arg.ARGFILE));
+ argparser = ArgParser.parseArgFiles(
+ bootstrapArgs.getList(Arg.ARGFILE),
+ bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS));
}
else
{
- argparser = new ArgParser(args);
+ argparser = new ArgParser(args,
+ bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS));
}
if (!Platform.isJS())
SSANNOTATION, NOTEMPFAC, TEMPFAC, TEMPFAC_LABEL, TEMPFAC_DESC,
TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP, NOSTRUCTURE, STRUCTURE, IMAGE,
QUIT, CLOSE, DEBUG("d"), QUIET("q"), ARGFILE, INCREMENT, NPP("n++"),
- SUBSTITUTIONS, NIL, SPLASH, SETARGFILE, UNSETARGFILE;
+ SUBSTITUTIONS, INITSUBSTITUTIONS, NIL, SPLASH, SETARGFILE, UNSETARGFILE;
protected static enum Opt
{
INCREMENT.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION);
NPP.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION);
SUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.MULTI, Opt.NOACTION);
+ INITSUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.BOOTSTRAP, Opt.NOACTION);
NIL.setOptions(Opt.UNARY, Opt.LINKED, Opt.MULTI, Opt.NOACTION);
SETARGFILE.setOptions(Opt.STRING, Opt.MULTI, Opt.PRIVATE, Opt.NOACTION);
UNSETARGFILE.setOptions(Opt.MULTI, Opt.PRIVATE, Opt.NOACTION);
public ArgParser(String[] args)
{
+ this(args, false);
+ }
+
+ public ArgParser(String[] args, boolean initsubstitutions)
+ {
// Make a mutable new ArrayList so that shell globbing parser works.
// (When shell file globbing is used, there are a sequence of non-Arg
// arguments (which are the expanded globbed filenames) that need to be
// consumed by the --open/--argfile/etc Arg which is most easily done by
// removing these filenames from the list one at a time. This can't be done
// with an ArrayList made with only Arrays.asList(String[] args). )
- this(new ArrayList<>(Arrays.asList(args)));
+ this(new ArrayList<>(Arrays.asList(args)), initsubstitutions);
}
- public ArgParser(List<String> args)
+ public ArgParser(List<String> args, boolean initsubstitutions)
{
- this(args, false);
+ this(args, initsubstitutions, false);
}
- public ArgParser(List<String> args, boolean allowPrivate)
+ public ArgParser(List<String> args, boolean initsubstitutions,
+ boolean allowPrivate)
{
// do nothing if there are no "--" args and some "-" args
boolean d = false;
if (d && !dd)
{
// leave it to the old style -- parse an empty list
- parse(new ArrayList<String>(), allowPrivate);
+ parse(new ArrayList<String>(), false, false);
return;
}
- parse(args, allowPrivate);
+ parse(args, initsubstitutions, allowPrivate);
}
- private void parse(List<String> args, boolean allowPrivate)
+ private void parse(List<String> args, boolean initsubstitutions,
+ boolean allowPrivate)
{
+ this.substitutions = initsubstitutions;
int argIndex = 0;
boolean openEachInitialFilenames = true;
for (int i = 0; i < args.size(); i++)
return new SubVals(item);
}
- public static ArgParser parseArgFiles(List<String> argFilenameGlobs)
+ public static ArgParser parseArgFiles(List<String> argFilenameGlobs,
+ boolean initsubstitutions)
{
List<File> argFiles = new ArrayList<>();
argFiles.addAll(FileUtils.getFilesFromGlob(pattern));
}
- return parseArgFileList(argFiles);
+ return parseArgFileList(argFiles, initsubstitutions);
}
- public static ArgParser parseArgFileList(List<File> argFiles)
+ public static ArgParser parseArgFileList(List<File> argFiles,
+ boolean initsubstitutions)
{
List<String> argsList = new ArrayList<>();
for (File argFile : argFiles)
Jalview.exit(message, 3);
}
}
- // Second param "true" uses Opt.PRIVATE args --setargile=argfile and
+ // Third param "true" uses Opt.PRIVATE args --setargile=argfile and
// --unsetargfile
- return new ArgParser(argsList, true);
+ return new ArgParser(argsList, initsubstitutions, true);
}
}
\ No newline at end of file
lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST"));
}
- @Test(groups = "Functional")
- public void argFilesGlobAndSubstitutionsTest() throws IOException
+ @Test(groups = "Functional", dataProvider = "argfileOutputFiles")
+ public void argFilesGlobAndSubstitutionsTest(String cmdLine,
+ String[] filenames) throws IOException
{
- cleanupArgfilesImages();
- String cmdLine = "--argfile=" + testfiles + "/dir*/argfile.txt";
+ cleanupFiles(filenames);
String[] args = cmdLine.split("\\s+");
Jalview.main(args);
Commands cmds = Jalview.getInstance().getCommands();
- File file1 = new File(png1);
- File file2 = new File(png2);
- Assert.assertTrue(file1.exists(),
- "Did not make file " + png1 + " from argfile");
- Assert.assertTrue(file2.exists(),
- "Did not make file " + png2 + " from argfile");
- long size1 = Files.size(file1.toPath());
- long size2 = Files.size(file2.toPath());
- Assert.assertTrue(file1.isFile() && size1 > 0);
- Assert.assertTrue(file2.isFile() && size2 > 0);
- Assert.assertTrue(size2 > size1); // png2 has three sequences, png1 has 2
- cleanupArgfilesImages();
+ Assert.assertNotNull(cmds);
+ File lastFile = null;
+ for (String filename : filenames)
+ {
+ File file = new File(filename);
+ Assert.assertTrue(file.exists(), "File '" + filename
+ + "' was not created by '" + cmdLine + "'");
+ Assert.assertTrue(file.isFile(), "File '" + filename
+ + "' is not a file from '" + cmdLine + "'");
+ Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
+ + "' has no content from '" + cmdLine + "'");
+ // make sure the successive output files get bigger!
+ if (lastFile != null)
+ Assert.assertTrue(
+ Files.size(file.toPath()) > Files.size(lastFile.toPath()));
+ }
+ cleanupFiles(filenames);
+ tearDown();
+ }
+
+ @DataProvider(name = "argfileOutputFiles")
+ public Object[][] argfileOutputFiles()
+ {
+ return new Object[][] {
+ { "--argfile=" + testfiles + "/**/*.txt", new String[]
+ { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png",
+ testfiles + "/dir3/subdir/test0.png" } },
+ { "--argfile=" + testfiles + "/**/argfile.txt", new String[]
+ { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
+ { "--argfile=" + testfiles + "/dir*/argfile.txt", new String[]
+ { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } },
+ { "--initsubstitutions --open examples/uniref50.fa --image "
+ + testfiles + "/{basename}.png",
+ new String[]
+ { testfiles + "/uniref50.png" } },
+ { "--open examples/uniref50.fa --image " + testfiles
+ + "/{basename}.png",
+ new String[]
+ { testfiles + "/{basename}.png" } } };
}
@DataProvider(name = "cmdLines")
return false;
}
- public static void cleanupArgfilesImages()
+ public static void cleanupFiles(String[] filenames)
{
- File png1File = new File(png1);
- File png2File = new File(png2);
- if (png1File.exists())
- {
- png1File.delete();
- }
- if (png2File.exists())
+ for (String filename : filenames)
{
- png2File.delete();
+ File file = new File(filename);
+ if (file.exists())
+ {
+ file.delete();
+ }
}
}
--- /dev/null
+--substitutions
+--increment
+--open={argfiledirname}/*.fa
+--colour=gecos:flower
+--image={argfiledirname}/{basename}.png
+--close
--- /dev/null
+>TEST0
+AAAA
--- /dev/null
+>TEST1
+AAAA
--- /dev/null
+>TEST2
+LLLL
--- /dev/null
+>TEST3
+AAARG