Class CLIUtils


  • public class CLIUtils
    extends java.lang.Object
    CLIUtils provides utility functions
    • Constructor Summary

      Constructors 
      Constructor Description
      CLIUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Converter<java.lang.String,​java.lang.String> argumentQuoteForOperatingSystem​(java.lang.String type)  
      static Converter<java.lang.String,​java.lang.String> characterEscapeForOperatingSystem​(java.lang.String type)  
      static boolean containsQuote​(java.lang.String arg)  
      static boolean containsSpace​(java.lang.String arg)  
      static java.lang.String escapeUnixShellChars​(java.lang.String str)  
      static void escapeUnixShellChars​(java.lang.StringBuilder out, java.lang.String str, java.lang.String unixShellChars)  
      static java.lang.String escapeUnixShellChars​(java.lang.String str, java.lang.String shellChars)  
      static java.lang.String generateArgline​(java.lang.String scriptpath, java.lang.String[] args)
      Create an appropriately quoted argline to use given the command (script path) and argument strings.
      static java.lang.String generateArgline​(java.lang.String scriptpath, java.lang.String[] args, java.lang.Boolean unsafe)
      Create an appropriately quoted argline to use given the command (script path) and argument strings.
      static java.lang.String generateArgline​(java.lang.String scriptpath, java.lang.String[] args, java.lang.String separator, java.lang.Boolean unsafe)
      Create an appropriately quoted argline to use given the command (script path) and argument strings.
      static java.lang.String quoteUnixShellArg​(java.lang.String arg)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • stringContainsWhitespacePredicate

        public static final java.util.function.Predicate<java.lang.String> stringContainsWhitespacePredicate
        evaluates to true if a string contains a space
      • stringContainsQuotePredicate

        public static final java.util.function.Predicate<java.lang.String> stringContainsQuotePredicate
        evaluates to true if a string contains a quote
      • UNIX_ARGUMENT_QUOTE

        public static final Converter<java.lang.String,​java.lang.String> UNIX_ARGUMENT_QUOTE
        Converter that can escape shell-special characters
      • UNIX_SHELL_ESCAPE

        public static final Converter<java.lang.String,​java.lang.String> UNIX_SHELL_ESCAPE
        Converter that can escape shell-special characters
      • UNIX_SHELL_CHARS

        public static final java.lang.String UNIX_SHELL_CHARS
        See Also:
        Constant Field Values
      • UNIX_SHELL_CHARS_NO_QUOTES

        public static final java.lang.String UNIX_SHELL_CHARS_NO_QUOTES
        See Also:
        Constant Field Values
    • Constructor Detail

      • CLIUtils

        public CLIUtils()
    • Method Detail

      • generateArgline

        public static java.lang.String generateArgline​(java.lang.String scriptpath,
                                                       java.lang.String[] args)
        Create an appropriately quoted argline to use given the command (script path) and argument strings.
        Parameters:
        scriptpath - path to command or script
        args - arguments to pass to the command
        Returns:
        a String of the command followed by the arguments, where each item which has spaces is appropriately quoted. Pre-quoted items are not changed during "unsafe" quoting. At this point in time, default behavior is "unsafe" quoting.
      • generateArgline

        public static java.lang.String generateArgline​(java.lang.String scriptpath,
                                                       java.lang.String[] args,
                                                       java.lang.Boolean unsafe)
        Create an appropriately quoted argline to use given the command (script path) and argument strings.
        Parameters:
        scriptpath - path to command or script
        args - arguments to pass to the command
        unsafe - whether to use backwards-compatible, known-insecure quoting
        Returns:
        a String of the command followed by the arguments, where each item which has spaces is appropriately quoted. Pre-quoted items are not changed during "unsafe" quoting.
      • generateArgline

        public static java.lang.String generateArgline​(java.lang.String scriptpath,
                                                       java.lang.String[] args,
                                                       java.lang.String separator,
                                                       java.lang.Boolean unsafe)
        Create an appropriately quoted argline to use given the command (script path) and argument strings.
        Parameters:
        scriptpath - path to command or script
        args - arguments to pass to the command
        separator - character to use to separate arguments
        unsafe - whether to use backwards-compatible, known-insecure quoting
        Returns:
        a String of the command followed by the arguments, where each item which has spaces is appropriately quoted. Pre-quoted items are not changed during "unsafe" quoting.
      • containsSpace

        public static boolean containsSpace​(java.lang.String arg)
        Parameters:
        arg - string
        Returns:
        true if the string contains any whitespace
      • containsQuote

        public static boolean containsQuote​(java.lang.String arg)
        Parameters:
        arg - string
        Returns:
        true if the string contains any whitespace
      • quoteUnixShellArg

        public static java.lang.String quoteUnixShellArg​(java.lang.String arg)
      • characterEscapeForOperatingSystem

        public static Converter<java.lang.String,​java.lang.String> characterEscapeForOperatingSystem​(java.lang.String type)
      • argumentQuoteForOperatingSystem

        public static Converter<java.lang.String,​java.lang.String> argumentQuoteForOperatingSystem​(java.lang.String type)
      • escapeUnixShellChars

        public static java.lang.String escapeUnixShellChars​(java.lang.String str)
      • escapeUnixShellChars

        public static java.lang.String escapeUnixShellChars​(java.lang.String str,
                                                            java.lang.String shellChars)
      • escapeUnixShellChars

        public static void escapeUnixShellChars​(java.lang.StringBuilder out,
                                                java.lang.String str,
                                                java.lang.String unixShellChars)