-
Notifications
You must be signed in to change notification settings - Fork 246
Bugfix/cli 221 add Option.Builder.listValueSeparator() #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
a1d4bc5
b0b1985
ceacf03
82c1273
bda84d2
e3d6c39
481d45f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,9 @@ private static Class<?> toType(final Class<?> type) { | |
| /** The character that is the value separator. */ | ||
| private char valueSeparator; | ||
|
|
||
| /** multiple values are within a single argument separated by valueSeparator char */ | ||
| private boolean valueSeparatorUsedForSingleArgument; | ||
|
|
||
| /** | ||
| * Constructs a new {@code Builder} with the minimum required parameters for an {@code Option} instance. | ||
| * | ||
|
|
@@ -326,7 +329,9 @@ public Builder valueSeparator() { | |
| } | ||
|
|
||
| /** | ||
| * The Option will use {@code sep} as a means to separate argument values. | ||
| * The Option will use {@code sep} as a means to separate java-property-style argument values. | ||
| * | ||
| * Method is mutually exclusive to listValueSeparator() method. | ||
| * <p> | ||
| * <strong>Example:</strong> | ||
| * </p> | ||
|
|
@@ -342,6 +347,10 @@ public Builder valueSeparator() { | |
| * String propertyValue = line.getOptionValues("D")[1]; // will be "value" | ||
| * </pre> | ||
| * | ||
| * In the above example, followup arguments are interpreted | ||
| * to be additional values to this option, needs to be terminated with -- so that | ||
| * others options or args can follow. | ||
| * | ||
| * @param valueSeparator The value separator. | ||
| * @return this builder. | ||
| */ | ||
|
|
@@ -350,6 +359,51 @@ public Builder valueSeparator(final char valueSeparator) { | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * The Option will use ',' to invoke listValueSeparator() | ||
| * | ||
| * @since 1.11.0 | ||
| * @return this builder. | ||
| */ | ||
| public Builder listValueSeparator() { | ||
| return listValueSeparator(Char.COMMA); | ||
| } | ||
|
|
||
| /** | ||
| * defines the separator used to split a list of values passed in a single argument. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A sentence should start with a capital letter. |
||
| * | ||
| * Method is mutually exclusive to valueSeparator() method. In the resulting option, | ||
| * isValueSeparatorUsedForSingleArgument() will return true. | ||
| * | ||
| * <p> | ||
| * <strong>Example:</strong> | ||
| * </p> | ||
| * | ||
| * <pre> | ||
| * final Option colors = Option.builder().option("c").hasArgs().listValueSeparator('|').build(); | ||
| * final Options options = new Options(); | ||
| * options.addOption(colors); | ||
| * | ||
| * final String[] args = {"-c", "red|blue|yellow", "b,c"}; | ||
| * final DefaultParser parser = new DefaultParser(); | ||
| * final CommandLine commandLine = parser.parse(options, args, null, true); | ||
| * final String [] colorValues = commandLine.getOptionValues(colors); | ||
| * // colorValues[0] will be "red" | ||
| * // colorValues[1] will be "blue" | ||
| * // colorValues[2] will be "yellow" | ||
| * final String arguments = commandLine.getArgs()[0]; // will be b,c | ||
| * | ||
| * </pre> | ||
| * | ||
| * @since 1.11.0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The since tag should be after the param tags. |
||
| * @param listValueSeparator The char to be used to split the argument into mulitple values. | ||
| * @return this builder. | ||
| */ | ||
| public Builder listValueSeparator(final char listValueSeparator) { | ||
| this.valueSeparator = listValueSeparator; | ||
| this.valueSeparatorUsedForSingleArgument = true; | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| /** Empty array. */ | ||
|
|
@@ -430,6 +484,9 @@ public static Builder builder(final String option) { | |
| /** The character that is the value separator. */ | ||
| private char valueSeparator; | ||
|
|
||
| /** multiple values are within a single argument separated by valueSeparator char */ | ||
| private boolean valueSeparatorUsedForSingleArgument; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A sentence should start with a capital letter. |
||
|
|
||
| /** | ||
| * Private constructor used by the nested Builder class. | ||
| * | ||
|
|
@@ -452,6 +509,7 @@ private Option(final Builder builder) { | |
| this.type = builder.type; | ||
| this.valueSeparator = builder.valueSeparator; | ||
| this.converter = builder.converter; | ||
| this.valueSeparatorUsedForSingleArgument = builder.valueSeparatorUsedForSingleArgument; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -834,6 +892,27 @@ public boolean isRequired() { | |
| return required; | ||
| } | ||
|
|
||
| /** | ||
| * Tests whether multiple values are expected in a single argument split by a separation character | ||
| * | ||
| * @return boolean true when the builder's listValueSeparator() method was used. Multiple values are expected in a single argument and | ||
| * are split by a separation character. | ||
| * @since 1.10.0 | ||
|
garydgregory marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public boolean isValueSeparatorUsedForSingleArgument() { | ||
| return valueSeparatorUsedForSingleArgument; | ||
| } | ||
|
|
||
| /** | ||
| * Set this to true to use the valueSeparator only on a single argument. See also builder's listValueSeparator() method. | ||
| * | ||
| * @param valueSeparatorUsedForSingleArgument the new value for this property | ||
| * @since 1.10.0 | ||
|
garydgregory marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public void setValueSeparatorUsedForSingleArgument(final boolean valueSeparatorUsedForSingleArgument) { | ||
| this.valueSeparatorUsedForSingleArgument = valueSeparatorUsedForSingleArgument; | ||
| } | ||
|
|
||
| /** | ||
| * Processes the value. If this Option has a value separator the value will have to be parsed into individual tokens. When n-1 tokens have been processed | ||
| * and there are more value separators in the value, parsing is ceased and the remaining characters are added as a single token. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A sentence should start with a capital letter.