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 Summary
Modifier and Type Method Description static booleancontains(String[] aArgs, String aArg)static org.refcodes.struct.Relation<String,String>getOptionArgument(Option<?> aOption, String[] aArgs, String[] aOptions)static booleanisOptionArgument(String aArg)static String[]toArgs(List<? extends Operand<?>>... aOperands)Takes allOperandinstances found in the providedLists and adds all therein found argument arrays (as ofOperand.getArgs()) to the result.static String[]toDiff(String[] aSet, String[] aSubset)Creates the difference between the provided set and the provided subset.static String[]toDiff(String[] aSet, List<? extends Operand<?>> aSubset)Creates the difference between the provided set and the providedLists therein found argument arrays subset (as ofOperand.getArgs()).static StringtoOptionsSpec(Operand<?> aOperand)Creates the options specification containing the short option (if any) and the long option ( if any) from the providedOperand;.static StringtoParameterSpec(Operand<?> aOperand)Creates the parameter specification from the providedOperand.static StringtoParameterSpec(Operand<?> aOperand, int aMin, int aMax)Creates the parameter specification from the providedOperand.static StringtoSpec(Operand<?> aOperand)Creates a specification for the givenOperandconsisting 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 providedStringstarts with one of the prefixes Identifying anOption. The prefixes are defined in theCommandArgPrefixenumeration 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 theRelationinstance. 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 allOperandinstances found in the providedLists 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 providedLists 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 theOperandinstances 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 theFlagimplies a parameter. If theOperandis an option, then the parameter will be prefixed and suffixed different to anOperandtype.- Parameters:
aOperand- The operand from which to get the parameter specification.- 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 theFlagimplies a parameter. If theOperandis an option, then the parameter will be prefixed and suffixed different to anOperandtype.- 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.
-
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.
-
toSpec
Creates a specification for the givenOperandconsisting of the options specification (if any) as oftoOptionsSpec(Operand)and the parameter specification (if any) as oftoParameterSpec(Operand).- Parameters:
aOperand- TheOperandfrom which to create the specification.- Returns:
- The specification.
-