Skip to content

[CLI-340] Add CommandLine.getParsedOptionValues()#334

Merged
garydgregory merged 5 commits into
apache:masterfrom
Claudenw:CLI-340_add_getParsedOptionValues
Nov 29, 2024
Merged

[CLI-340] Add CommandLine.getParsedOptionValues()#334
garydgregory merged 5 commits into
apache:masterfrom
Claudenw:CLI-340_add_getParsedOptionValues

Conversation

@Claudenw

@Claudenw Claudenw commented Nov 12, 2024

Copy link
Copy Markdown
Contributor

Fix for CLI-340 (add getParsedOptionValues())
fix a minor formatting issue in Help javadoc.

@Claudenw Claudenw self-assigned this Nov 12, 2024
@Claudenw Claudenw marked this pull request as ready for review November 12, 2024 17:42

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Claudenw

  • See exception management comment (rebase on git master svp)
  • For all Javadoc of new methods: Can the method return null? If so, when? What happens if the option does not exist?
  • Are all these APIs really needed? Couldn't we just add a minimal set following the YAGNI principle. Not my use case, so you tell me ;-)

Comment thread src/main/java/org/apache/commons/cli/CommandLine.java Outdated

/**
* Gets a version of this {@code Option} converted to an array of a particular type.
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the method return null? If so, when? What happens if the option does not exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with all the value getter methods if the option is not in the command line null is returned unless the default value is defined.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then please update the Javadoc instead of writing it up here ;-)

* @see PatternOptionBuilder
* @since 1.10.0
*/
public <T> T[] getParsedOptionValues(final char opt) throws ParseException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to abbreviate IMO: opt -> option. Also, using opt in Javadoc makes for awkward reading.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am following the pattern used in the class. Methods from earlier versions used opt, I elected to do the same.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's slightly awkward (to me) to read "@param opt the name of the option." If 'opt' is the name, then why not call it 'name' or 'optionName'? Might as well do the best we can for new code. We can fix the rest separately if you want or do it all in this PR since.

@Claudenw

Claudenw commented Nov 12, 2024

Copy link
Copy Markdown
Contributor Author

For all Javadoc of new methods: Can the method return null? If so, when? What happens if the option does not exist?

I updated the javadoc to reflect the null or default value return as appropriate. I also updated the javadoc for the getParsedOptionValue() methods.

Are all these APIs really needed? Couldn't we just add a minimal set following the YAGNI principle. Not my use case, so you tell me ;-)

There are all here because they follow the same pattern as getParsedOptionValue() methods. I think they need to be here because V1 supports all those access methods for getOptionValue, getParsedOptionValue, and getOptionValues.

I think that in V2 I would limit each set to 4 implementations getOptionValue(Option), getOptionValue(OptionGroup), getOptionValue(Option, default), and getOptionValue(OptionGroup, default). The char and String versions are just fluff. I think that since the application has to create the Options it can keep them around and use them directly without referring to the char or String versions keys.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Claudenw

I've added 3 comments.

Comment thread src/main/java/org/apache/commons/cli/CommandLine.java Outdated

/**
* Gets a version of this {@code Option} converted to an array of a particular type.
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then please update the Javadoc instead of writing it up here ;-)

* @see PatternOptionBuilder
* @since 1.10.0
*/
public <T> T[] getParsedOptionValues(final char opt) throws ParseException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's slightly awkward (to me) to read "@param opt the name of the option." If 'opt' is the name, then why not call it 'name' or 'optionName'? Might as well do the best we can for new code. We can fix the rest separately if you want or do it all in this PR since.

@Claudenw Claudenw force-pushed the CLI-340_add_getParsedOptionValues branch from d1df605 to a55b1ff Compare November 13, 2024 00:04
@Claudenw

Copy link
Copy Markdown
Contributor Author

If you want me to change "opt" to "option" throughout the CommandLine class I'll do it. But having some method params be "opt" and others be "option" seems sloppy.

@garydgregory

Copy link
Copy Markdown
Member

If you want me to change "opt" to "option" throughout the CommandLine class I'll do it. But having some method params be "opt" and others be "option" seems sloppy.

Hi @Claudenw
I don't want to give you more work so I'll leave it up to you and it could be done later.

@Claudenw

Copy link
Copy Markdown
Contributor Author

@garydgregory Let's fix the naming in V2.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll make the trivial changes mentioned later.

@garydgregory garydgregory merged commit 764c148 into apache:master Nov 29, 2024
@garydgregory garydgregory changed the title Fix for CLI-340 [CLI-340] CommandLine.getParsedOptionValues() Nov 29, 2024
@garydgregory garydgregory changed the title [CLI-340] CommandLine.getParsedOptionValues() [CLI-340] Add 'CommandLine.getParsedOptionValues() Nov 29, 2024
@garydgregory garydgregory changed the title [CLI-340] Add 'CommandLine.getParsedOptionValues() [CLI-340] Add CommandLine.getParsedOptionValues() Nov 29, 2024
ann-hav added a commit to havochvatten/symphony-import that referenced this pull request Jun 27, 2025
Specifically we'll need this feature from the upcoming v1.10 of commons-cli:
apache/commons-cli#334

The assumption here is that the release should be available *reasonably soon*. No release date has been announced, but going by the pace of previous releases and the activity/minor version diff it seems .
It was either this or patch the class implementation temporarily, doing this seemed like the better option.
Collaborators/testers need to obtain a prebuilt package or build from source in the meantime.
dongjoon-hyun added a commit to apache/spark that referenced this pull request Aug 4, 2025
### What changes were proposed in this pull request?

This PR aims to upgrade `commons-cli` to 1.10.0 which is the first release tested with **Java 25-ea**.

### Why are the changes needed?

To bring the latest improvements and bug fixes.
- https://commons.apache.org/proper/commons-cli/changes.html#a1.10.0 (2025-07-30)
  - [Run Java 24 and 25-ea](apache/commons-cli@e6a611f)
  - [[CLI-333] org.apache.commons.cli.Option.Builder implements](apache/commons-cli@c9698e6)
  - apache/commons-cli#314
  - apache/commons-cli#334
  - [[CLI-341] HelpFormatter infinite loop with 0 width input](apache/commons-cli@bce0f6a)
  - [[CLI-343] OptionFormatter.getBothOpt() lacks validation for Options](apache/commons-cli@859d5e5)
  - [[CLI-344] Option.processValue() throws NullPointerException when passed](apache/commons-cli@4e0cdd0)
  - [[CLI-347] Options.addOptionGroup(OptionGroup) does not remove required](apache/commons-cli@42be792)
  - [[CLI-349] DefaultParser.parse() throws NullPointerException when options](apache/commons-cli@ff678b0)

### Does this PR introduce _any_ user-facing change?

No behavior change.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #51816 from dongjoon-hyun/SPARK-53102.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun added a commit to apache/orc that referenced this pull request Aug 4, 2025
### What changes were proposed in this pull request?

This PR aims to upgrade `commons-cli` to 1.10.0 which is the first release tested with Java 25-ea.

### Why are the changes needed?

To bring the latest improvements and bug fixes.
- https://commons.apache.org/proper/commons-cli/changes.html#a1.10.0 (2025-07-30)
  - [Run Java 24 and 25-ea](apache/commons-cli@e6a611f)
  - [[CLI-333] org.apache.commons.cli.Option.Builder implements](apache/commons-cli@c9698e6)
  - apache/commons-cli#314
  - apache/commons-cli#334
  - [[CLI-341] HelpFormatter infinite loop with 0 width input](apache/commons-cli@bce0f6a)
  - [[CLI-343] OptionFormatter.getBothOpt() lacks validation for Options](apache/commons-cli@859d5e5)
  - [[CLI-344] Option.processValue() throws NullPointerException when passed](apache/commons-cli@4e0cdd0)
  - [[CLI-347] Options.addOptionGroup(OptionGroup) does not remove required](apache/commons-cli@42be792)
  - [[CLI-349] DefaultParser.parse() throws NullPointerException when options](apache/commons-cli@ff678b0)

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #2349 from dongjoon-hyun/ORC-1968.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun added a commit to apache/orc that referenced this pull request Aug 4, 2025
### What changes were proposed in this pull request?

This PR aims to upgrade `commons-cli` to 1.10.0 which is the first release tested with Java 25-ea.

### Why are the changes needed?

To bring the latest improvements and bug fixes.
- https://commons.apache.org/proper/commons-cli/changes.html#a1.10.0 (2025-07-30)
  - [Run Java 24 and 25-ea](apache/commons-cli@e6a611f)
  - [[CLI-333] org.apache.commons.cli.Option.Builder implements](apache/commons-cli@c9698e6)
  - apache/commons-cli#314
  - apache/commons-cli#334
  - [[CLI-341] HelpFormatter infinite loop with 0 width input](apache/commons-cli@bce0f6a)
  - [[CLI-343] OptionFormatter.getBothOpt() lacks validation for Options](apache/commons-cli@859d5e5)
  - [[CLI-344] Option.processValue() throws NullPointerException when passed](apache/commons-cli@4e0cdd0)
  - [[CLI-347] Options.addOptionGroup(OptionGroup) does not remove required](apache/commons-cli@42be792)
  - [[CLI-349] DefaultParser.parse() throws NullPointerException when options](apache/commons-cli@ff678b0)

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #2349 from dongjoon-hyun/ORC-1968.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 7a1a34f)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants