Class CliUtility

java.lang.Object
org.refcodes.cli.CliUtility

public final class CliUtility extends Object
This utility class provides method useful for the refcodes-cli artifact and whose implementation has been motivated by the implementation of the refcodes-cli artifact.
  • Method Details

    • contains

      public static boolean contains(String[] aArgs, String aArg)
      Determines whether a given String is contained in the given String array.
      Parameters:
      aArgs - The String array to be tested whether it contains the given String.
      aArg - The String to be tested whether it is contained in the provided String array.
      Returns:
      True in case the String is contained in the array, else false.
    • isOptionArgument

      public static boolean isOptionArgument(String aArg)
      Determines whether the provided String starts with one of the prefixes Identifying an Option. The prefixes are defined in the CommandArgPrefix enumeration and are usually the single hyphen-minus "-" and the double hyphen-minus "--". Usually option arguments are prefixed either with a
      Parameters:
      aArg - The argument for which to determines whether it represents an option argument or not.
      Returns:
      True, in case the provided argument is an option argument.
    • getOptionArgument

      public static org.refcodes.struct.Relation<String,String> getOptionArgument(Option<?> aOption, String[] aArgs, String[] aOptions)
      Takes the Option's short-option and long-option and tries to determine that Option's value in the provided command line arguments. Depending on whether the short-option or the long-option was detected with a value, the result contains the according option as the key with the detected value in the Relation instance. Null is returned when either no option was found or no value for one of the options.
      Parameters:
      aOption - The option for which to get the value
      aArgs - The command line arguments from which to determine the Option's value.
      aOptions - The list of options (short and well as long) which are reserved and cannot be used as value.
      Returns:
      A key/value-pair containing the detected (short / long) option alongside the detected value.
    • toArgs

      @SafeVarargs public static String[] toArgs(List<? extends Operand<?>>... aOperands)
      Takes all Operand instances found in the provided Lists and adds all therein found argument arrays (as of Operand.getArgs()) to the result.
      Parameters:
      aOperands - The lists containing the Operand instances whose command line arguments are to be added to the result.
      Returns:
      All the command line arguments detected in the provided Operands Lists.
    • toDiff

      public static String[] toDiff(String[] aSet, String[] aSubset)
      Creates the difference between the provided set and the provided subset.
      Parameters:
      aSet - The set to be used for the diff operation.
      aSubset - The subset to be used for the diff operation.
      Returns:
      The difference between the set and the subset.
    • toDiff

      public static String[] toDiff(String[] aSet, List<? extends Operand<?>> aSubset)
      Creates the difference between the provided set and the provided Lists therein found argument arrays subset (as of Operand.getArgs()).
      Parameters:
      aSet - The set to be used for the diff operation.
      aSubset - The subset to be used for the diff operation being the lists containing the Operand instances whose command line arguments are to be diffed.
      Returns:
      The difference between the set and the subset.
    • toParameterSpec

      public static String toParameterSpec(Operand<?> aOperand)
      Creates the parameter specification from the provided Operand. In case we got a Flag, then there will be an empty parameter specification as the Flag implies a parameter. If the Operand is an option, then the parameter will be prefixed and suffixed different to an Operand type.
      Parameters:
      aOperand - The operand from which to get the parameter specification.
      Returns:
      The parameter specification.
    • toParameterSpec

      public static String toParameterSpec(Operand<?> aOperand, String aParamEscCode, String aResetEscCode)
      Creates the parameter specification from the provided Operand. In case we got a Flag, then there will be an empty parameter specification as the Flag implies a parameter. If the Operand is an option, then the parameter will be prefixed and suffixed different to an Operand type.
      Parameters:
      aOperand - The operand from which to get the parameter specification.
      aParamEscCode - The escape code to be used when processing a argument, e.g. this can be an ANSI Escape-Code to highlight the option and/or parameters.
      aResetEscCode - The escape code to close (reset) any Escape-Code being set before.
      Returns:
      The parameter specification.
    • toParameterSpec

      public static String toParameterSpec(Operand<?> aOperand, int aMin, int aMax)
      Creates the parameter specification from the provided Operand. In case we got a Flag, then there will be an empty parameter specification as the Flag implies a parameter. If the Operand is an option, then the parameter will be prefixed and suffixed different to an Operand type.
      Parameters:
      aOperand - The operand from which to get the parameter specification.
      aMin - The minimum value for the operand.
      aMax - The maximum value for the operand.
      Returns:
      The parameter specification.
    • toParameterSpec

      public static String toParameterSpec(Operand<?> aOperand, int aMin, int aMax, String aParamEscCode, String aResetEscCode)
      Creates the parameter specification from the provided Operand. In case we got a Flag, then there will be an empty parameter specification as the Flag implies a parameter. If the Operand is an option, then the parameter will be prefixed and suffixed different to an Operand type.
      Parameters:
      aOperand - The operand from which to get the parameter specification.
      aMin - The minimum value for the operand.
      aMax - The maximum value for the operand.
      aParamEscCode - The escape code to be used when processing a argument, e.g. this can be an ANSI Escape-Code to highlight the option and/or parameters.
      aResetEscCode - The escape code to close (reset) any Escape-Code being set before.
      Returns:
      The parameter specification.
    • toShortSpec

      public static String toShortSpec(Operand<?> aOperand)
      Creates a specification for the given Operand consisting of the short option specification (if any) or the long option specification(if any) and the parameter specification (if any) as of toParameterSpec(Operand).
      Parameters:
      aOperand - The Operand from which to create the specification.
      Returns:
      The specification.
    • toShortSpec

      public static String toShortSpec(Operand<?> aOperand, String aOptEscCode, String aParamEscCode, String aResetEscCode)
      Creates a specification for the given Operand consisting of the short option specification (if any) or the long option specification(if any) and the parameter specification (if any) as of toParameterSpec(Operand).
      Parameters:
      aOperand - The Operand from which to create the specification.
      aOptEscCode - The escape code to be used when processing an option, e.g. this can be an ANSI Escape-Code to highlight the option.
      aParamEscCode - The escape code to be used when processing a argument, e.g. this can be an ANSI Escape-Code to highlight the option and/or parameters.
      aResetEscCode - The escape code to close (reset) any Escape-Code being set before.
      Returns:
      The specification.
    • toShortOptionsSpec

      public static String toShortOptionsSpec(Operand<?> aOperand)
      Creates the options specification containing the short option only (if any) or(!) the long option (if any) from the provided Operand.
      Parameters:
      aOperand - The operand from which to create the options specification.
      Returns:
      The options specification String.
    • toShortOptionsSpec

      public static String toShortOptionsSpec(Operand<?> aOperand, String aOptEscCode, String aResetEscCode)
      Creates the options specification containing the short option only (if any) or(!) the long option (if any) from the provided Operand.
      Parameters:
      aOperand - The operand from which to create the options specification.
      aOptEscCode - The escape code to be used when processing an option, e.g. this can be an ANSI Escape-Code to highlight the option.
      aResetEscCode - The escape code to close (reset) any Escape-Code being set before.
      Returns:
      The options specification String.
    • toOptionsSpec

      public static String toOptionsSpec(Operand<?> aOperand)
      Creates the options specification containing the short option (if any) and the long option (if any) from the provided Operand.
      Parameters:
      aOperand - The operand from which to create the options specification.
      Returns:
      The options specification String.
    • toOptionsSpec

      public static String toOptionsSpec(Operand<?> aOperand, String aOptEscCode, String aResetEscCode)
      Creates the options specification containing the short option (if any) and the long option (if any) from the provided Operand.
      Parameters:
      aOperand - The operand from which to create the options specification.
      aOptEscCode - The escape code to be used when processing an option, e.g. this can be an ANSI Escape-Code to highlight the option.
      aResetEscCode - The escape code to close (reset) any Escape-Code being set before.
      Returns:
      The options specification String.
    • toSpec

      public static String toSpec(Operand<?> aOperand)
      Creates a specification for the given Operand consisting of the options specification (if any) as of toOptionsSpec(Operand) and the parameter specification (if any) as of toParameterSpec(Operand).
      Parameters:
      aOperand - The Operand from which to create the specification.
      Returns:
      The specification.
    • toSpec

      public static String toSpec(Operand<?> aOperand, String aOptEscCode, String aParamEscCode, String aResetEscCode)
      Creates a specification for the given Operand consisting of the options specification (if any) as of toOptionsSpec(Operand) and the parameter specification (if any) as of toParameterSpec(Operand).
      Parameters:
      aOperand - The Operand from which to create the specification.
      aOptEscCode - The escape code to be used when processing an option, e.g. this can be an ANSI Escape-Code to highlight the option.
      aParamEscCode - The escape code to be used when processing an argument, e.g. this can be an ANSI Escape-Code to highlight the parameters.
      aResetEscCode - The escape code to close (reset) any Escape-Code being set before.
      Returns:
      The specification.