java.lang.Object
de.iip_ecosphere.platform.support.setup.CmdLine

public class CmdLine extends Object
Simple command line utilities. May be backed by a real command line parser.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • CmdLine

      public CmdLine()
  • Method Details

    • parseToArgs

      public static void parseToArgs(String text, List<String> cmds)
      Parses given text into individual arguments considering double quotes for string escapement with space as a command separator.
      Parameters:
      text - the text to parse
      cmds - the commands (to be modified as a side effect)
    • parseToArgs

      public static void parseToArgs(String text, List<String> cmds, char separator)
      Parses given text into individual arguments considering double quotes for string escapement and a given command separator.
      Parameters:
      text - the text to parse
      cmds - the commands (to be modified as a side effect)
      separator - the separator (usually ' ')
    • getArg

      public static String getArg(String[] args, String argName, String dflt)
      Emulates reading a Spring-like parameter if the configuration is not yet in place.
      Parameters:
      args - the arguments
      argName - the argument name (without PARAM_PREFIX or PARAM_VALUE_SEP)
      dflt - the default value if the argument cannot be found
      Returns:
      the value of argument or dflt
    • getIntArg

      public static int getIntArg(String[] args, String argName, int dflt)
      Returns an int command line argument.
      Parameters:
      args - the arguments
      argName - the argument name (without PARAM_PREFIX or PARAM_VALUE_SEP)
      dflt - the default value if the argument cannot be found
      Returns:
      the value of argument or dflt
    • getBooleanArg

      public static boolean getBooleanArg(String[] args, String argName, boolean dflt)
      Returns a Boolean command line argument.
      Parameters:
      args - the arguments
      argName - the argument name (without PARAM_PREFIX or PARAM_VALUE_SEP)
      dflt - the default value if the argument cannot be found
      Returns:
      the value of argument or dflt
    • toArgs

      public static String[] toArgs(String args)
      Turns a command line string into arguments. Considers usual quotes.
      Parameters:
      args - the arguments as string
      Returns:
      the parsed arguments
    • composeArgument

      public static String composeArgument(String name, Object value)
      Composes a command line argument.
      Parameters:
      name - the name of the argument
      value - the value of the argument
      Returns:
      the composed argument
    • hasArgument

      public static boolean hasArgument(String[] args, String argName, boolean includeNoValueArg, boolean includeValueArg)
      Returns whether there is an argument with/without a no-value argument of the given name.
      Parameters:
      args - the arguments
      argName - the argument name (without PARAM_PREFIX or PARAM_VALUE_SEP)
      includeNoValueArg - if a no-value argument --name be considered
      includeValueArg - if a value argument --name shall be considered
      Returns:
      true if found, false else
    • getBooleanArgNoVal

      public static boolean getBooleanArgNoVal(String[] args, String argName, boolean dflt)
      Returns a Boolean command line argument including a potential no-value argument.
      Parameters:
      args - the arguments
      argName - the argument name (without PARAM_PREFIX or PARAM_VALUE_SEP)
      dflt - the default value if the argument cannot be found
      Returns:
      the value of argument or deft
    • extractArgNames

      public static String[] extractArgNames(String[] args)
      Extracts the argument names of those arguments complying with PARAM_PREFIX and PARAM_VALUE_SEP from args.
      Parameters:
      args - the arguments
      Returns:
      the extracted complying argument names, no values are contained; may be empty for no complying args