[spring-extensions] branch main updated: Bury ANSI codes behind a more insulated API.

Scott Cantor cantor.2 at osu.edu
Wed Oct 14 13:41:49 UTC 2020


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository spring-extensions.

View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=1259416712ff2a5d77de62c516bea779d5e926bc

The following commit(s) were added to refs/heads/main by this push:
       new  1259416   Bury ANSI codes behind a more insulated API.
1259416 is described below

commit 1259416712ff2a5d77de62c516bea779d5e926bc
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 14 09:41:43 2020 -0400

    Bury ANSI codes behind a more insulated API.
---
 .../ext/spring/cli/AbstractCommandLine.java        | 60 ++++++++++++----------
 .../spring/cli/AbstractCommandLineArguments.java   | 10 ++++
 .../ext/spring/cli/CommandLineArguments.java       |  9 +++-
 3 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java b/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java
index 9750967..cc27bcc 100644
--- a/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java
+++ b/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLine.java
@@ -75,51 +75,57 @@ public abstract class AbstractCommandLine<T extends CommandLineArguments> {
     /** Return code indicating an unknown error occurred, {@value} . */
     public static final int RC_UNKNOWN = -1;
 
-    /** ANSI color codes. */
-    public enum ANSIColors {
+    /** Terminal codes. */
+    public enum TerminalCodes {
         
-        /** ANSI reset. */
-        ANSI_RESET("\u001B[0m"),
+        /** Reset. */
+        RESET("\u001B[0m"),
 
-        /** ANSI black. */
-        ANSI_BLACK("\u001B[30m"),
+        /** Black. */
+        BLACK("\u001B[30m"),
         
-        /** ANSI red. */
-        ANSI_RED("\u001B[31m"),
+        /** Red. */
+        RED("\u001B[31m"),
         
-        /** ANSI red. */
-        ANSI_GREEN("\u001B[32m"),
+        /** Green. */
+        GREEN("\u001B[32m"),
         
-        /** ANSI red. */
-        ANSI_YELLOW("\u001B[33m"),
+        /** Yellow. */
+        YELLOW("\u001B[33m"),
         
-        /** ANSI red. */
-        ANSI_BLUE("\u001B[34m"),
+        /** Blue. */
+        BLUE("\u001B[34m"),
         
-        /** ANSI red. */
-        ANSI_PURPLE("\u001B[35m"),
+        /** Purple. */
+        PURPLE("\u001B[35m"),
         
-        /** ANSI red. */
-        ANSI_CYAN("\u001B[36m"),
+        /** Cyan. */
+        CYAN("\u001B[36m"),
         
-        /** ANSI red. */
-        ANSI_WHITE("\u001B[37m");
+        /** White. */
+        WHITE("\u001B[37m");
         
         /** Code string. */
-        @Nonnull @NotEmpty private final String codestring;
+        @Nonnull @NotEmpty private final String ansicode;
         
         /**
          * Constructor.
          *
-         * @param s code string
+         * @param ansi ANSI code string
          */
-        ANSIColors(@Nonnull @NotEmpty final String s) {
-            codestring = s;
+        TerminalCodes(@Nonnull @NotEmpty final String ansi) {
+            ansicode = ansi;
         }
         
-        /** {@inheritDoc} */
-        public String toString() {
-            return codestring;
+        /**
+         * Gets the relevant code for the enum value.
+         * 
+         * @param args CLI arguments
+         * 
+         * @return code string value
+         */
+        public String code(@Nonnull final CommandLineArguments args) {
+            return args.isANSI() ? ansicode : "";
         }
     };
     
diff --git a/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLineArguments.java b/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLineArguments.java
index cf3a1e3..863726b 100644
--- a/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLineArguments.java
+++ b/src/main/java/net/shibboleth/ext/spring/cli/AbstractCommandLineArguments.java
@@ -76,6 +76,10 @@ public abstract class AbstractCommandLineArguments implements CommandLineArgumen
     @Parameter(names = "--version")
     private boolean version;
 
+    /** Use ANSI color codes. */
+    @Parameter(names = "--ansi")
+    private boolean ansi;
+    
     /** Spring property sources. */
     @Parameter(names = "--propertyFiles")
     @Nonnull @NonnullElements private List<String> propertySources = new ArrayList<>();
@@ -115,6 +119,11 @@ public abstract class AbstractCommandLineArguments implements CommandLineArgumen
         return version;
     }
     
+    /** {@inheritDoc} */
+    public boolean isANSI() {
+        return ansi;
+    }
+    
     /** {@inheritDoc} */
     @Nonnull @NonnullElements @Unmodifiable @NotLive public List<String> getPropertyFiles() {
         return propertySources;
@@ -151,6 +160,7 @@ public abstract class AbstractCommandLineArguments implements CommandLineArgumen
         out.println();
         out.println(String.format("  --%-20s %s", "help", "Prints this help information"));
         out.println(String.format("  --%-20s %s", "version", "Prints version"));
+        out.println(String.format("  --%-20s %s", "ansi", "Use ANSI color codes"));
         out.println(String.format("  --%-20s %s", "lang", "Language range for i18n"));
         out.println(String.format("  --%-20s %s", "propertyFiles", "Comma-separated list of Spring property files"));
         out.println();
diff --git a/src/main/java/net/shibboleth/ext/spring/cli/CommandLineArguments.java b/src/main/java/net/shibboleth/ext/spring/cli/CommandLineArguments.java
index 80337a8..782d231 100644
--- a/src/main/java/net/shibboleth/ext/spring/cli/CommandLineArguments.java
+++ b/src/main/java/net/shibboleth/ext/spring/cli/CommandLineArguments.java
@@ -61,10 +61,17 @@ public interface CommandLineArguments {
     /**
      * Indicates the presence of the <code>--version</code> option.
      *
-     * @return <code>true</code> if the user requested the version be printed.
+     * @return <code>true</code> if the user requested the version be printed
      */
     boolean isVersion();
 
+    /**
+     * Indicates the presence of the <code>--ansi</code> option.
+     * 
+     * @return <code>true</code> if the user requested the ANSI code option
+     */
+    boolean isANSI();
+
     /**
      * Get list of property filenames to load.
      * 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list