Merge branch 'bug/JAL-4277_dirname_substitution_always_absolute' into improvement...
[jalview.git] / src / jalview / bin / argparser / ArgParser.java
index 41189b8..b300c67 100644 (file)
@@ -37,6 +37,7 @@ import java.util.Map;
 import jalview.bin.Cache;
 import jalview.bin.Console;
 import jalview.bin.Jalview;
+import jalview.bin.Jalview.ExitCode;
 import jalview.bin.argparser.Arg.Opt;
 import jalview.bin.argparser.Arg.Type;
 import jalview.util.FileUtils;
@@ -171,6 +172,15 @@ public class ArgParser
 
   private BootstrapArgs bootstrapArgs = null;
 
+  private boolean oldArguments = false;
+
+  private boolean mixedArguments = false;
+
+  /**
+   * saved examples of mixed arguments
+   */
+  private String[] mixedExamples = new String[] { null, null };
+
   static
   {
     argMap = new HashMap<>();
@@ -235,19 +245,39 @@ public class ArgParser
       if (arg.startsWith(DOUBLEDASH))
       {
         dd = true;
-        break;
+        if (mixedExamples[1] == null)
+        {
+          mixedExamples[1] = arg;
+        }
       }
       else if (arg.startsWith("-") || arg.equals("open"))
       {
         d = true;
+        if (mixedExamples[0] == null)
+        {
+          mixedExamples[0] = arg;
+        }
+      }
+    }
+    if (d)
+    {
+      if (dd)
+      {
+        mixedArguments = true;
+      }
+      else
+      {
+        oldArguments = true;
       }
     }
-    if (d && !dd)
+
+    if (oldArguments || mixedArguments)
     {
       // leave it to the old style -- parse an empty list
       parse(new ArrayList<String>(), false, false);
       return;
     }
+
     if (bsa != null)
       this.bootstrapArgs = bsa;
     else
@@ -373,10 +403,12 @@ public class ArgParser
         {
           // arg not found
           Console.error("Argument '" + arg + "' not recognised.  Exiting.");
-          Jalview.exit("Invalid argument used." + System.lineSeparator()
-                  + "Use" + System.lineSeparator() + "jalview "
-                  + Arg.HELP.argString() + System.lineSeparator()
-                  + "for a usage statement.", 13);
+          Jalview.exit(
+                  "Invalid argument used." + System.lineSeparator() + "Use"
+                          + System.lineSeparator() + "jalview "
+                          + Arg.HELP.argString() + System.lineSeparator()
+                          + "for a usage statement.",
+                  ExitCode.INVALID_ARGUMENT);
           continue;
         }
         if (a.hasOption(Opt.PRIVATE) && !allowPrivate)
@@ -892,7 +924,7 @@ public class ArgParser
       {
         String message = Arg.ARGFILE.argString() + EQUALS + "\""
                 + argFile.getPath() + "\": File does not exist.";
-        Jalview.exit(message, 2);
+        Jalview.exit(message, ExitCode.FILE_NOT_FOUND);
       }
       try
       {
@@ -906,7 +938,7 @@ public class ArgParser
       {
         String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath()
                 + "\": File could not be read.";
-        Jalview.exit(message, 3);
+        Jalview.exit(message, ExitCode.FILE_NOT_READABLE);
       }
     }
     // Third param "true" uses Opt.PRIVATE args --setargile=argfile and
@@ -932,7 +964,7 @@ public class ArgParser
         String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath()
                 + "\": File could not be read.";
         Console.debug(message, e);
-        Jalview.exit(message, 3);
+        Jalview.exit(message, ExitCode.FILE_NOT_READABLE);
       }
     }
     return args;
@@ -1320,4 +1352,18 @@ public class ArgParser
     return linkedArgs.get(linkedId);
   }
 
+  public boolean isOldStyle()
+  {
+    return oldArguments;
+  }
+
+  public boolean isMixedStyle()
+  {
+    return mixedArguments;
+  }
+
+  public String[] getMixedExamples()
+  {
+    return mixedExamples;
+  }
 }
\ No newline at end of file