package jalview.bin.argparser;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import jalview.bin.argparser.Arg.Opt;
import jalview.util.FileUtils;
// only need one
private Map<Arg, List<String>> bootstrapArgMap = new HashMap<>();
+ private Set<File> argFiles = new HashSet<>();
+
public static BootstrapArgs getBootstrapArgs(String[] args)
{
List<String> argList = new ArrayList<>(Arrays.asList(args));
private BootstrapArgs(List<String> args)
{
- parse(args);
+ parse(args, null);
}
- private void parse(List<String> args)
+ private void parse(List<String> args, File inArgFile)
{
if (args == null)
return;
+ // avoid looping argFiles
+ if (inArgFile != null)
+ {
+ if (argFiles.contains(inArgFile))
+ {
+ System.err.println(
+ "Looped argfiles detected: '" + inArgFile.getPath() + "'");
+ return;
+ }
+ argFiles.add(inArgFile);
+ }
+
for (int i = 0; i < args.size(); i++)
{
String arg = args.get(i);
if (a.hasOption(Opt.STRING))
{
+ List<String> vals = null;
if (equalPos == -1)
{
- addAll(a, ArgParser.getShellGlobbedFilenameValues(a, args,
- i + 1));
+ vals = ArgParser.getShellGlobbedFilenameValues(a, args, i + 1);
}
else
{
if (a.hasOption(Opt.GLOB))
{
- addAll(a, FileUtils.getFilenamesFromGlob(val));
+ vals = FileUtils.getFilenamesFromGlob(val);
}
else
{
- add(a, val);
+ vals = new ArrayList<>();
+ vals.add(val);
+ }
+ }
+ addAll(a, vals);
+
+ if (a == Arg.ARGFILE)
+ {
+ for (String filename : vals)
+ {
+ File argFile = new File(filename);
+ parse(ArgParser.readArgFile(argFile), argFile);
}
}
}