JAL-629 More consistent printing of --arguments. Example nf-core argfile
[jalview.git] / src / jalview / bin / argparser / ArgParser.java
index 7d4f187..ff238da 100644 (file)
@@ -29,7 +29,6 @@ import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 
 import jalview.bin.Console;
@@ -107,7 +106,8 @@ public class ArgParser
         if (argMap.containsKey(argName))
         {
           Console.warn("Trying to add argument name multiple times: '"
-                  + argName + "'"); // RESTORE THIS WHEN MERGED
+                  + argName + "'"); // RESTORE THIS WHEN
+          // MERGED
           if (argMap.get(argName) != a)
           {
             Console.error(
@@ -189,7 +189,7 @@ public class ArgParser
       if (openEachInitialFilenames && !arg.startsWith(DOUBLEDASH)
               && !arg.startsWith("-") && new File(arg).exists())
       {
-        arg = DOUBLEDASH + Arg.OPENNEW.getName();
+        arg = Arg.OPENNEW.argString();
       }
       else
       {
@@ -242,8 +242,8 @@ public class ArgParser
         }
         if (a.hasOption(Opt.PRIVATE) && !allowPrivate)
         {
-          Console.error("Argument '" + DOUBLEDASH + argName
-                  + "' is private. Ignoring.");
+          Console.error(
+                  "Argument '" + a.argString() + "' is private. Ignoring.");
           continue;
         }
         if (!a.hasOption(Opt.BOOLEAN) && negated)
@@ -256,7 +256,7 @@ public class ArgParser
         if (!a.hasOption(Opt.STRING) && equalPos > -1)
         {
           // set --argname=value when arg does not accept values
-          Console.error("Argument '" + DOUBLEDASH + argName
+          Console.error("Argument '" + a.argString()
                   + "' does not expect a value (given as '" + arg
                   + "').  Ignoring.");
           continue;
@@ -264,7 +264,7 @@ public class ArgParser
         if (!a.hasOption(Opt.LINKED) && linkedId != null)
         {
           // set --argname[linkedId] when arg does not use linkedIds
-          Console.error("Argument '" + DOUBLEDASH + argName
+          Console.error("Argument '" + a.argString()
                   + "' does not expect a linked id (given as '" + arg
                   + "'). Ignoring.");
           continue;
@@ -403,7 +403,7 @@ public class ArgParser
         // not dealing with both NODUPLICATEVALUES and GLOB
         if (a.hasOption(Opt.NODUPLICATEVALUES) && avm.hasValue(a, val))
         {
-          Console.error("Argument '" + DOUBLEDASH + argName
+          Console.error("Argument '" + a.argString()
                   + "' cannot contain a duplicate value ('" + val
                   + "'). Ignoring this and subsequent occurrences.");
           continue;
@@ -414,7 +414,7 @@ public class ArgParser
         String id = idsv.get(ArgValues.ID);
         if (id != null && avm.hasId(a, id))
         {
-          Console.error("Argument '" + DOUBLEDASH + argName
+          Console.error("Argument '" + a.argString()
                   + "' has a duplicate id ('" + id + "'). Ignoring.");
           continue;
         }
@@ -534,12 +534,11 @@ public class ArgParser
   /*
    * A helper method to take a list of String args where we're expecting
    * {"--previousargs", "--arg", "file1", "file2", "file3", "--otheroptionsornot"}
-   * and the index of the globbed arg, here 1.  It returns a
-   * List<String> {"file1", "file2", "file3"}
-   * *and remove these from the original list object* so that processing
-   * can continue from where it has left off, e.g. args has become
-   * {"--previousargs", "--arg", "--otheroptionsornot"}
-   * so the next increment carries on from the next --arg if available.
+   * and the index of the globbed arg, here 1. It returns a List<String> {"file1",
+   * "file2", "file3"} *and remove these from the original list object* so that
+   * processing can continue from where it has left off, e.g. args has become
+   * {"--previousargs", "--arg", "--otheroptionsornot"} so the next increment
+   * carries on from the next --arg if available.
    */
   protected static List<String> getShellGlobbedFilenameValues(Arg a,
           List<String> args, int i)
@@ -658,25 +657,22 @@ public class ArgParser
     {
       if (!argFile.exists())
       {
-        String message = DOUBLEDASH
-                + Arg.ARGFILE.name().toLowerCase(Locale.ROOT) + EQUALS
-                + "\"" + argFile.getPath() + "\": File does not exist.";
+        String message = Arg.ARGFILE.argString() + EQUALS + "\""
+                + argFile.getPath() + "\": File does not exist.";
         Jalview.exit(message, 2);
       }
       try
       {
-        String setargfile = new StringBuilder(ArgParser.DOUBLEDASH)
-                .append(Arg.SETARGFILE.getName()).append(EQUALS)
-                .append(argFile.getCanonicalPath()).toString();
+        String setargfile = new StringBuilder(Arg.SETARGFILE.argString())
+                .append(EQUALS).append(argFile.getCanonicalPath())
+                .toString();
         argsList.add(setargfile);
         argsList.addAll(Files.readAllLines(Paths.get(argFile.getPath())));
-        argsList.add(new StringBuilder(ArgParser.DOUBLEDASH)
-                .append(Arg.UNSETARGFILE.getName()).toString());
+        argsList.add(Arg.UNSETARGFILE.argString());
       } catch (IOException e)
       {
-        String message = DOUBLEDASH
-                + Arg.ARGFILE.name().toLowerCase(Locale.ROOT) + "=\""
-                + argFile.getPath() + "\": File could not be read.";
+        String message = Arg.ARGFILE.argString() + "=\"" + argFile.getPath()
+                + "\": File could not be read.";
         Jalview.exit(message, 3);
       }
     }