Class Option.Builder
java.lang.Object
tripleo.vendor.org_apache_commons_cli.Option.Builder
- Enclosing class:
- Option
A nested builder class to create
Option instances using descriptive methods.
Example usage:
Option option = Option.builder("a").required(true).longOpt("arg-name").build();
- Since:
- 1.3
-
Method Summary
Modifier and TypeMethodDescription@NotNull Option.BuilderSets the display name for the argument value.@NotNull Optionbuild()Constructs an Option with the values declared by thisOption.Builder.@NotNull Option.BuilderSets the description for this option.@NotNull Option.BuilderhasArg()Indicates that the Option will require an argument.@NotNull Option.BuilderhasArg(boolean hasArg) Indicates if the Option has an argument or not.@NotNull Option.BuilderhasArgs()Indicates that the Option can have unlimited argument values.@NotNull Option.BuilderSets the long name of the Option.@NotNull Option.BuildernumberOfArgs(int numberOfArgs) Sets the number of argument values the Option can take.@NotNull Option.BuilderSets the name of the Option.@NotNull Option.BuilderoptionalArg(boolean isOptional) Sets whether the Option can have an optional argument.@NotNull Option.Builderrequired()Marks this Option as required.@NotNull Option.Builderrequired(boolean required) Sets whether the Option is mandatory.@NotNull Option.BuilderSets the type of the Option.@NotNull Option.BuilderThe Option will use '=' as a means to separate argument value.@NotNull Option.BuildervalueSeparator(char sep) The Option will usesepas a means to separate argument values.
-
Method Details
-
option
Sets the name of the Option.- Parameters:
option- the name of the Option- Returns:
- this builder, to allow method chaining
- Throws:
IllegalArgumentException- if there are any non valid Option characters inopt- Since:
- 1.5.0
-
argName
Sets the display name for the argument value.- Parameters:
argName- the display name for the argument value.- Returns:
- this builder, to allow method chaining
-
build
Constructs an Option with the values declared by thisOption.Builder.- Returns:
- the new
Option - Throws:
IllegalArgumentException- if neitheroptorlongOpthas been set
-
desc
Sets the description for this option.- Parameters:
description- the description of the option.- Returns:
- this builder, to allow method chaining
-
hasArg
Indicates that the Option will require an argument.- Returns:
- this builder, to allow method chaining
-
hasArg
Indicates if the Option has an argument or not.- Parameters:
hasArg- specifies whether the Option takes an argument or not- Returns:
- this builder, to allow method chaining
-
hasArgs
Indicates that the Option can have unlimited argument values.- Returns:
- this builder, to allow method chaining
-
longOpt
Sets the long name of the Option.- Parameters:
longOpt- the long name of the Option- Returns:
- this builder, to allow method chaining
-
numberOfArgs
Sets the number of argument values the Option can take.- Parameters:
numberOfArgs- the number of argument values- Returns:
- this builder, to allow method chaining
-
optionalArg
Sets whether the Option can have an optional argument.- Parameters:
isOptional- specifies whether the Option can have an optional argument.- Returns:
- this builder, to allow method chaining
-
required
Marks this Option as required.- Returns:
- this builder, to allow method chaining
-
required
Sets whether the Option is mandatory.- Parameters:
required- specifies whether the Option is mandatory- Returns:
- this builder, to allow method chaining
-
type
Sets the type of the Option.- Parameters:
type- the type of the Option- Returns:
- this builder, to allow method chaining
-
valueSeparator
The Option will use '=' as a means to separate argument value.- Returns:
- this builder, to allow method chaining
-
valueSeparator
The Option will usesepas a means to separate argument values.Example:
Option opt = Option.builder("D").hasArgs().valueSeparator('=').build(); Options options = new Options(); options.addOption(opt); String[] args = {"-Dkey=value"}; CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); String propertyName = line.getOptionValues("D")[0]; // will be "key" String propertyValue = line.getOptionValues("D")[1]; // will be "value"- Parameters:
sep- The value separator.- Returns:
- this builder, to allow method chaining
-