Class CommandLineExtracter
Object
CommandLineExtracter
Adds methods to
CommandLine for querying and extracting options, with and without
arguments.- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionCommandLineExtracter(org.apache.commons.cli.CommandLine line) Creates a newCommandLineExtracterinstance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIdentical toCommandLine.hasOption(java.lang.String).booleanhasOptionWithoutArgument(String option) Checks if an option exists, but without any argument(s) specified.voidifPresentMultiple(String optionName, CheckedConsumer<String[], ExperimentExecutionException> consumer) Executes aConsumerif an option is present - allowing that option to occur multiple times.voidifPresentSingle(String optionName, CheckedConsumer<String, ExperimentExecutionException> consumer) Executes aConsumerif an option is present - allowing that option to occur only once.
-
Constructor Details
-
CommandLineExtracter
public CommandLineExtracter(org.apache.commons.cli.CommandLine line) Creates a newCommandLineExtracterinstance.- Parameters:
line- The command-line from which options are extracted.
-
-
Method Details
-
hasOption
Identical toCommandLine.hasOption(java.lang.String).- Parameters:
option- short-name of option- Returns:
- true iff option exists on the command-line, irrespective of if arguments are present or not
-
hasOptionWithoutArgument
Checks if an option exists, but without any argument(s) specified.- Parameters:
option- short-name of option- Returns:
- true iff option exists on the command-line and no argument is specified.
-
ifPresentSingle
public void ifPresentSingle(String optionName, CheckedConsumer<String, ExperimentExecutionException> consumer) throws ExperimentExecutionExceptionExecutes aConsumerif an option is present - allowing that option to occur only once.- Parameters:
optionName- the short-name of the option, which should be capable of accepting a single-argumentconsumer- a consumer that accepts a single argument as a string, an empty-string if no argument is provided.- Throws:
ExperimentExecutionException- if thrown byconsumeror if the option is specified multiple times.
-
ifPresentMultiple
public void ifPresentMultiple(String optionName, CheckedConsumer<String[], ExperimentExecutionException> consumer) throws ExperimentExecutionExceptionExecutes aConsumerif an option is present - allowing that option to occur multiple times.- Parameters:
optionName- the short-name of the option, which should be capable of accepting a single-argumentconsumer- a consumer that accepts a single argument as a string, an empty-string if no argument is provided.- Throws:
ExperimentExecutionException- if thrown byconsumeror if the option is specified multiple times.
-