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 newCommandLineExtracter
instance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Identical toCommandLine.hasOption(java.lang.String)
.boolean
hasOptionWithoutArgument
(String option) Checks if an option exists, but without any argument(s) specified.void
ifPresentMultiple
(String optionName, CheckedConsumer<String[], ExperimentExecutionException> consumer) Executes aConsumer
if an option is present - allowing that option to occur multiple times.void
ifPresentSingle
(String optionName, CheckedConsumer<String, ExperimentExecutionException> consumer) Executes aConsumer
if an option is present - allowing that option to occur only once.
-
Constructor Details
-
CommandLineExtracter
public CommandLineExtracter(org.apache.commons.cli.CommandLine line) Creates a newCommandLineExtracter
instance.- 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 aConsumer
if 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 byconsumer
or if the option is specified multiple times.
-
ifPresentMultiple
public void ifPresentMultiple(String optionName, CheckedConsumer<String[], ExperimentExecutionException> consumer) throws ExperimentExecutionExceptionExecutes aConsumer
if 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 byconsumer
or if the option is specified multiple times.
-