Package org.apache.commons.cli
Class CommandLine.Builder
- java.lang.Object
-
- org.apache.commons.cli.CommandLine.Builder
-
- Enclosing class:
- CommandLine
public static final class CommandLine.Builder extends java.lang.Object
A nested builder class to createCommandLine
instance using descriptive methods.- Since:
- 1.4
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
args
The unrecognized options/arguments(package private) static java.util.function.Consumer<Option>
DEPRECATED_HANDLER
Prints an Option toSystem.out
.private java.util.function.Consumer<Option>
deprecatedHandler
Deprecated Option handler.private java.util.List<Option>
options
The processed options
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandLine.Builder
addArg(java.lang.String arg)
Adds left-over unrecognized option/argument.CommandLine.Builder
addOption(Option opt)
Adds an option to the command line.CommandLine
build()
Creates the new instance.CommandLine.Builder
setDeprecatedHandler(java.util.function.Consumer<Option> deprecatedHandler)
Sets the deprecated option handler.
-
-
-
Field Detail
-
DEPRECATED_HANDLER
static final java.util.function.Consumer<Option> DEPRECATED_HANDLER
Prints an Option toSystem.out
.
-
args
private final java.util.List<java.lang.String> args
The unrecognized options/arguments
-
options
private final java.util.List<Option> options
The processed options
-
deprecatedHandler
private java.util.function.Consumer<Option> deprecatedHandler
Deprecated Option handler.
-
-
Method Detail
-
addArg
public CommandLine.Builder addArg(java.lang.String arg)
Adds left-over unrecognized option/argument.- Parameters:
arg
- the unrecognized option/argument.- Returns:
- this Builder instance for method chaining.
-
addOption
public CommandLine.Builder addOption(Option opt)
Adds an option to the command line. The values of the option are stored.- Parameters:
opt
- the processed option.- Returns:
- this Builder instance for method chaining.
-
build
public CommandLine build()
Creates the new instance.- Returns:
- the new instance.
-
setDeprecatedHandler
public CommandLine.Builder setDeprecatedHandler(java.util.function.Consumer<Option> deprecatedHandler)
Sets the deprecated option handler.- Parameters:
deprecatedHandler
- the deprecated option handler.- Returns:
- this.
- Since:
- 1.7.0
-
-