JAL-629 More NG arguments: --features, --annotations, --sortbytree, --tree, --groovy...
[jalview.git] / src / jalview / bin / argparser / ArgParser.java
index f1781fc..dd863d1 100644 (file)
@@ -98,8 +98,9 @@ public class ArgParser
   private static final String ARGFILEDIRNAME = "{argfiledirname}";
 
   // flag to say whether {n} subtitutions in output filenames should be made.
-  // Turn on and off with --subs and --nosubs
-  private boolean substitutions = false;
+  // Turn on and off with --substitutions and --nosubstitutions
+  // Start with it on
+  private boolean substitutions = true;
 
   // flag to say whether the default linkedId is the current default linked id
   // or ALL linkedIds
@@ -117,6 +118,8 @@ public class ArgParser
 
   private int argIndex = 0;
 
+  private BootstrapArgs bootstrapArgs = null;
+
   static
   {
     argMap = new HashMap<>();
@@ -146,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
@@ -157,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")
@@ -190,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);
   }
 
@@ -346,11 +355,7 @@ public class ArgParser
 
         // make NOACTION adjustments
         // default and auto counter increments
-        if (a == Arg.NEWFRAME)
-        {
-          defaultLinkedIdCounter++;
-        }
-        else if (a == Arg.NPP)
+        if (a == Arg.NPP)
         {
           linkedIdAutoCounter++;
         }
@@ -366,11 +371,18 @@ public class ArgParser
         {
           argFile = null;
         }
-        else if (a == Arg.ALLFRAMES)
+        else if (a == Arg.ALL)
         {
           allLinkedIds = !negated;
         }
 
+        // this is probably only Arg.NEW and Arg.OPEN
+        if (a.hasOption(Opt.INCREMENTDEFAULTCOUNTER))
+        {
+          // use the next default prefixed OPENLINKEDID
+          defaultLinkedId(true);
+        }
+
         String autoCounterString = null;
         boolean usingAutoCounterLinkedId = false;
         String defaultLinkedId = defaultLinkedId(false);
@@ -379,11 +391,6 @@ public class ArgParser
         {
           if (linkedId == null)
           {
-            if (a.hasOption(Opt.INCREMENTDEFAULTCOUNTER))
-            {
-              // use the next default prefixed OPENLINKEDID
-              defaultLinkedId = defaultLinkedId(true);
-            }
             if (allLinkedIds && a.hasOption(Opt.ALLOWALL))
             {
               linkedId = MATCHALLLINKEDIDS;
@@ -419,7 +426,7 @@ public class ArgParser
           }
         }
 
-        // do not continue for NOACTION args
+        // do not continue in this block for NOACTION args
         if (a.hasOption(Opt.NOACTION))
           continue;
 
@@ -621,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)
@@ -632,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))
     {
@@ -699,7 +721,7 @@ public class ArgParser
   }
 
   public static ArgParser parseArgFiles(List<String> argFilenameGlobs,
-          boolean initsubstitutions)
+          boolean initsubstitutions, BootstrapArgs bsa)
   {
     List<File> argFiles = new ArrayList<>();
 
@@ -709,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)
@@ -741,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)