java.lang.Object
org.refcodes.cli.CliUtility
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 Summary
Modifier and TypeMethodDescriptionstatic boolean
getOptionArgument
(Option<?> aOption, String[] aArgs, String[] aOptions) static boolean
isOptionArgument
(String aArg) static String[]
Takes allOperand
instances found in the providedList
s and adds all therein found argument arrays (as ofOperand.getArgs()
) to the result.static String[]
Creates the difference between the provided set and the provided subset.static String[]
Creates the difference between the provided set and the providedList
s therein found argument arrays subset (as ofOperand.getArgs()
).static String
toOptionsSpec
(Operand<?> aOperand) Creates the options specification containing the short option (if any) and the long option (if any) from the providedOperand
.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 providedOperand
.static String
toParameterSpec
(Operand<?> aOperand) Creates the parameter specification from the providedOperand
.static String
toParameterSpec
(Operand<?> aOperand, int aMin, int aMax) Creates the parameter specification from the providedOperand
.static String
toParameterSpec
(Operand<?> aOperand, int aMin, int aMax, String aParamEscCode, String aResetEscCode) Creates the parameter specification from the providedOperand
.static String
toParameterSpec
(Operand<?> aOperand, String aParamEscCode, String aResetEscCode) Creates the parameter specification from the providedOperand
.static String
toShortOptionsSpec
(Operand<?> aOperand) Creates the options specification containing the short option only (if any) or(!)static String
toShortOptionsSpec
(Operand<?> aOperand, String aOptEscCode, String aResetEscCode) Creates the options specification containing the short option only (if any) or(!)static String
toShortSpec
(Operand<?> aOperand) Creates a specification for the givenOperand
consisting of the short option specification (if any) or the long option specification(if any) and the parameter specification (if any) as oftoParameterSpec(Operand)
.static String
toShortSpec
(Operand<?> aOperand, String aOptEscCode, String aParamEscCode, String aResetEscCode) Creates a specification for the givenOperand
consisting of the short option specification (if any) or the long option specification(if any) and the parameter specification (if any) as oftoParameterSpec(Operand)
.static String
Creates a specification for the givenOperand
consisting of the options specification (if any) as oftoOptionsSpec(Operand)
and the parameter specification (if any) as oftoParameterSpec(Operand)
.static String
Creates a specification for the givenOperand
consisting of the options specification (if any) as oftoOptionsSpec(Operand)
and the parameter specification (if any) as oftoParameterSpec(Operand)
.
-
Method Details
-
contains
-
isOptionArgument
Determines whether the providedString
starts with one of the prefixes Identifying anOption
. The prefixes are defined in theCommandArgPrefix
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 theOption
's short-option and long-option and tries to determine thatOption
'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 theRelation
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 valueaArgs
- The command line arguments from which to determine theOption
'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
Takes allOperand
instances found in the providedList
s and adds all therein found argument arrays (as ofOperand.getArgs()
) to the result. -
toDiff
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
Creates the difference between the provided set and the providedList
s therein found argument arrays subset (as ofOperand.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 theOperand
instances whose command line arguments are to be diffed.- Returns:
- The difference between the set and the subset.
-
toParameterSpec
Creates the parameter specification from the providedOperand
. In case we got aFlag
, then there will be an empty parameter specification as theFlag
implies a parameter. If theOperand
is an option, then the parameter will be prefixed and suffixed different to anOperand
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 providedOperand
. In case we got aFlag
, then there will be an empty parameter specification as theFlag
implies a parameter. If theOperand
is an option, then the parameter will be prefixed and suffixed different to anOperand
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
Creates the parameter specification from the providedOperand
. In case we got aFlag
, then there will be an empty parameter specification as theFlag
implies a parameter. If theOperand
is an option, then the parameter will be prefixed and suffixed different to anOperand
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 providedOperand
. In case we got aFlag
, then there will be an empty parameter specification as theFlag
implies a parameter. If theOperand
is an option, then the parameter will be prefixed and suffixed different to anOperand
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
Creates a specification for the givenOperand
consisting of the short option specification (if any) or the long option specification(if any) and the parameter specification (if any) as oftoParameterSpec(Operand)
.- Parameters:
aOperand
- TheOperand
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 givenOperand
consisting of the short option specification (if any) or the long option specification(if any) and the parameter specification (if any) as oftoParameterSpec(Operand)
.- Parameters:
aOperand
- TheOperand
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
Creates the options specification containing the short option only (if any) or(!) the long option (if any) from the providedOperand
.- 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 providedOperand
.- 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
Creates the options specification containing the short option (if any) and the long option (if any) from the providedOperand
.- Parameters:
aOperand
- The operand from which to create the options specification.- Returns:
- The options specification
String
.
-
toOptionsSpec
Creates the options specification containing the short option (if any) and the long option (if any) from the providedOperand
.- 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
Creates a specification for the givenOperand
consisting of the options specification (if any) as oftoOptionsSpec(Operand)
and the parameter specification (if any) as oftoParameterSpec(Operand)
.- Parameters:
aOperand
- TheOperand
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 givenOperand
consisting of the options specification (if any) as oftoOptionsSpec(Operand)
and the parameter specification (if any) as oftoParameterSpec(Operand)
.- Parameters:
aOperand
- TheOperand
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.
-