com.dtolabs.rundeck.core.cli
Class CLIUtils

java.lang.Object
  extended by com.dtolabs.rundeck.core.cli.CLIUtils

public class CLIUtils
extends java.lang.Object

CLIUtils provides utility functions


Field Summary
static org.apache.commons.collections.Predicate stringContainsQuotePredicate
          evaluates to true if a string contains a quote
static org.apache.commons.collections.Predicate stringContainsWhitespacePredicate
          evaluates to true if a string contains a space
static Converter<java.lang.String,java.lang.String> UNIX_ARGUMENT_QUOTE
          Converter that can escape shell-special characters
static Converter<java.lang.String,java.lang.String> UNIX_SHELL_ESCAPE
          Converter that can escape shell-special characters
 
Constructor Summary
CLIUtils()
           
 
Method Summary
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)
          Return true if the string contains any whitespace
static boolean containsSpace(java.lang.String arg)
          Return true if the string contains any whitespace
static java.lang.String escapeUnixShellChars(java.lang.String str)
           
static void escapeUnixShellChars(java.lang.StringBuilder out, java.lang.String str)
           
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 org.apache.commons.collections.Predicate stringContainsWhitespacePredicate
evaluates to true if a string contains a space


stringContainsQuotePredicate

public static final org.apache.commons.collections.Predicate 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

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)
Return true if the string contains any whitespace

Parameters:
arg -
Returns:

containsQuote

public static boolean containsQuote(java.lang.String arg)
Return true if the string contains any whitespace

Parameters:
arg -
Returns:

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 void escapeUnixShellChars(java.lang.StringBuilder out,
                                        java.lang.String str)