JAL-629 More NG arguments: --features, --annotations, --sortbytree, --tree, --groovy...
[jalview.git] / src / jalview / bin / argparser / ArgParser.java
index 42868ae..dd863d1 100644 (file)
@@ -118,6 +118,8 @@ public class ArgParser
 
   private int argIndex = 0;
 
+  private BootstrapArgs bootstrapArgs = null;
+
   static
   {
     argMap = new HashMap<>();
@@ -147,10 +149,11 @@ public class ArgParser
 
   public ArgParser(String[] args)
   {
-    this(args, false);
+    this(args, false, null);
   }
 
-  public ArgParser(String[] args, boolean initsubstitutions)
+  public ArgParser(String[] args, boolean initsubstitutions,
+          BootstrapArgs bsa)
   {
     // Make a mutable new ArrayList so that shell globbing parser works.
     // (When shell file globbing is used, there are a sequence of non-Arg
@@ -158,16 +161,17 @@ public class ArgParser
     // consumed by the --append/--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)), initsubstitutions);
+    this(new ArrayList<>(Arrays.asList(args)), initsubstitutions, false,
+            bsa);
   }
 
   public ArgParser(List<String> args, boolean initsubstitutions)
   {
-    this(args, initsubstitutions, false);
+    this(args, initsubstitutions, false, null);
   }
 
   public ArgParser(List<String> args, boolean initsubstitutions,
-          boolean allowPrivate)
+          boolean allowPrivate, BootstrapArgs bsa)
   {
     // do nothing if there are no "--" args and (some "-" args || >0 arg is
     // "open")
@@ -191,6 +195,10 @@ public class ArgParser
       parse(new ArrayList<String>(), false, false);
       return;
     }
+    if (bsa != null)
+      this.bootstrapArgs = bsa;
+    else
+      this.bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
     parse(args, initsubstitutions, allowPrivate);
   }
 
@@ -620,9 +628,24 @@ public class ArgParser
     return vals;
   }
 
+  public BootstrapArgs getBootstrapArgs()
+  {
+    return bootstrapArgs;
+  }
+
   public boolean isSet(Arg a)
   {
-    return a.hasOption(Opt.LINKED) ? isSet("", a) : isSet(null, a);
+    return a.hasOption(Opt.LINKED) ? isSetAtAll(a) : isSet(null, a);
+  }
+
+  public boolean isSetAtAll(Arg a)
+  {
+    for (String linkedId : linkedOrder)
+    {
+      if (isSet(linkedId, a))
+        return true;
+    }
+    return false;
   }
 
   public boolean isSet(String linkedId, Arg a)
@@ -631,7 +654,7 @@ public class ArgParser
     return avm == null ? false : avm.containsArg(a);
   }
 
-  public boolean getBool(Arg a)
+  public boolean getBoolean(Arg a)
   {
     if (!a.hasOption(Opt.BOOLEAN) && !a.hasOption(Opt.UNARY))
     {
@@ -698,7 +721,7 @@ public class ArgParser
   }
 
   public static ArgParser parseArgFiles(List<String> argFilenameGlobs,
-          boolean initsubstitutions)
+          boolean initsubstitutions, BootstrapArgs bsa)
   {
     List<File> argFiles = new ArrayList<>();
 
@@ -708,11 +731,11 @@ public class ArgParser
       argFiles.addAll(FileUtils.getFilesFromGlob(pattern));
     }
 
-    return parseArgFileList(argFiles, initsubstitutions);
+    return parseArgFileList(argFiles, initsubstitutions, bsa);
   }
 
   public static ArgParser parseArgFileList(List<File> argFiles,
-          boolean initsubstitutions)
+          boolean initsubstitutions, BootstrapArgs bsa)
   {
     List<String> argsList = new ArrayList<>();
     for (File argFile : argFiles)
@@ -740,7 +763,7 @@ public class ArgParser
     }
     // Third param "true" uses Opt.PRIVATE args --setargile=argfile and
     // --unsetargfile
-    return new ArgParser(argsList, initsubstitutions, true);
+    return new ArgParser(argsList, initsubstitutions, true, bsa);
   }
 
   protected static List<String> readArgFile(File argFile)