Class CmdLine
java.lang.Object
de.iip_ecosphere.platform.support.setup.CmdLine
Simple command line utilities. May be backed by a real command line parser.
- Author:
- Holger Eichelberger, SSE
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcomposeArgument(String name, Object value) Composes a command line argument.static String[]extractArgNames(String[] args) Extracts the argument names of those arguments complying withPARAM_PREFIXandPARAM_VALUE_SEPfromargs.static StringEmulates reading a Spring-like parameter if the configuration is not yet in place.static booleangetBooleanArg(String[] args, String argName, boolean dflt) Returns a Boolean command line argument.static booleangetBooleanArgNoVal(String[] args, String argName, boolean dflt) Returns a Boolean command line argument including a potential no-value argument.static intReturns an int command line argument.static booleanhasArgument(String[] args, String argName, boolean includeNoValueArg, boolean includeValueArg) Returns whether there is an argument with/without a no-value argument of the givenname.static voidparseToArgs(String text, List<String> cmds) Parses giventextinto individual arguments considering double quotes for string escapement with space as a command separator.static voidparseToArgs(String text, List<String> cmds, char separator) Parses giventextinto individual arguments considering double quotes for string escapement and a given command separator.static String[]Turns a command line string into arguments.
-
Field Details
-
PARAM_PREFIX
- See Also:
-
PARAM_ARG_NAME_SEP
- See Also:
-
PARAM_VALUE_SEP
- See Also:
-
-
Constructor Details
-
CmdLine
public CmdLine()
-
-
Method Details
-
parseToArgs
Parses giventextinto individual arguments considering double quotes for string escapement with space as a command separator.- Parameters:
text- the text to parsecmds- the commands (to be modified as a side effect)
-
parseToArgs
Parses giventextinto individual arguments considering double quotes for string escapement and a given command separator.- Parameters:
text- the text to parsecmds- the commands (to be modified as a side effect)separator- the separator (usually ' ')
-
getArg
Emulates reading a Spring-like parameter if the configuration is not yet in place.- Parameters:
args- the argumentsargName- the argument name (withoutPARAM_PREFIXorPARAM_VALUE_SEP)dflt- the default value if the argument cannot be found- Returns:
- the value of argument or
dflt
-
getIntArg
Returns an int command line argument.- Parameters:
args- the argumentsargName- the argument name (withoutPARAM_PREFIXorPARAM_VALUE_SEP)dflt- the default value if the argument cannot be found- Returns:
- the value of argument or
dflt
-
getBooleanArg
Returns a Boolean command line argument.- Parameters:
args- the argumentsargName- the argument name (withoutPARAM_PREFIXorPARAM_VALUE_SEP)dflt- the default value if the argument cannot be found- Returns:
- the value of argument or
dflt
-
toArgs
Turns a command line string into arguments. Considers usual quotes.- Parameters:
args- the arguments as string- Returns:
- the parsed arguments
-
composeArgument
Composes a command line argument.- Parameters:
name- the name of the argumentvalue- 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 givenname.- Parameters:
args- the argumentsargName- the argument name (withoutPARAM_PREFIXorPARAM_VALUE_SEP)includeNoValueArg- if a no-value argument--namebe consideredincludeValueArg- if a value argument--nameshall be considered- Returns:
trueif found,falseelse
-
getBooleanArgNoVal
Returns a Boolean command line argument including a potential no-value argument.- Parameters:
args- the argumentsargName- the argument name (withoutPARAM_PREFIXorPARAM_VALUE_SEP)dflt- the default value if the argument cannot be found- Returns:
- the value of argument or
deft
-
extractArgNames
Extracts the argument names of those arguments complying withPARAM_PREFIXandPARAM_VALUE_SEPfromargs.- Parameters:
args- the arguments- Returns:
- the extracted complying argument names, no values are contained; may be empty for no complying args
-