Skip to content
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

Create new feature parameterAllowedBeforeEndOfOptions #2115

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ddsharpe
Copy link

@ddsharpe ddsharpe commented Sep 18, 2023

Create new feature parameterAllowedBeforeEndOfOptions to allow restricting positional parameters until after EndOfOptions. Enhancement for and fixes #2103

…cting positional parameters until after EndOfOptions
@ddsharpe ddsharpe closed this Sep 18, 2023
@ddsharpe ddsharpe reopened this Sep 19, 2023
@remkop remkop self-assigned this Sep 19, 2023
@ddsharpe
Copy link
Author

Are you waiting on something from me?

@remkop
Copy link
Owner

remkop commented Sep 27, 2023

Apologies. Family circumstances prevent me from working on my open source projects at the moment.

@ddsharpe
Copy link
Author

I am trying to decide if I should fork the project or wait. Do you have an ETA for your return to working on this project?

@remkop remkop added this to the 4.8 milestone Dec 14, 2023
Copy link
Owner

@remkop remkop left a comment

Choose a reason for hiding this comment

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

Sorry for the long delay. My mother passed away and I was not in the mood to work on picocli for a long time.

I have added some individual feedback to the commit changes:

/**
* Enhancement from issue 2103 enables or disables positional parameters before the EndOfOptions delimiter (such as "--").
*/
public class Issue2103 {
Copy link
Owner

Choose a reason for hiding this comment

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

Please also add tests to verify that

  • the CommandLine.setParameterAllowedBeforeEndOfOptions method returns true by default
  • calling setParameterAllowedBeforeEndOfOptions also impacts the existing subcommands
  • when subcommands are added after setParameterAllowedBeforeEndOfOptions is called, these added subcommands have the default value.

Please also add tests for the public ParserSpec parameterAllowedBeforeEndOfOptions getter and setter methods.

There may also be existing tests that need to be fixed since the output of ParserSpec::toString looks different now (which is good, by the way).

see https://github.com/remkop/picocli/blob/main/src/test/java/picocli/SubcommandTests.java#L776

Copy link
Owner

Choose a reason for hiding this comment

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

These two failing tests are probably caused by the change to ParserSpec::toString:

picocli.TracerTest > testTracingDebugWithSubCommands FAILED
    org.junit.ComparisonFailure at TracerTest.java:375

picocli.TracerTest > testDebugOutputForDoubleDashSeparatesPositionalParameters FAILED
    org.junit.ComparisonFailure at TracerTest.java:118

@@ -13932,6 +13964,10 @@ private void processPositionalParameter(Collection<ArgSpec> required, Set<ArgSpe
if (tracer.isDebug()) {
tracer.debug("Parser is configured to treat all unmatched options as positional parameter", arg);}
}
if (!endOfOptions && !commandSpec.parser().parameterAllowedBeforeEndOfOptions()) {
handleUnmatchedArgument(args);
Copy link
Owner

Choose a reason for hiding this comment

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

What error is shown to the end user when they violate this restriction?
Since the parser knows what went wrong, it should provide a hint to the user as to how they can fix the issue.

We should also have a test that verifies the error message.

Copy link
Author

Choose a reason for hiding this comment

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

Currently, it is Unmatched argument at index 5: 'a' where the index is the position of the "bad" input and 'a' is the value of the bad input. I assume that you would prefer a new message, perhaps like Unmatched argument at index 5: 'a'. Positional parameters must follow the "{EndOfOptions Character, like --}"

Copy link
Owner

Choose a reason for hiding this comment

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

Yes please!

How about:

Unmatched argument at index 5: 'a'. Positional parameters must follow the EndOfOptions delimiter '--'.

(The delimiter string is configurable, so the code that generates this error message should use get EndOfOptionsDelimiter instead of hardcoding the default --)

Copy link
Author

Choose a reason for hiding this comment

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

This change is a bit tricky due to the existing code flow. Please take a close look at this part of the change before approving.

/** Returns whether positional parameters on the command line are allowed to occur before the special End of Options delimiter.
* The default is {@code true}.
* @return {@code true} positional parameters may occur anywhere on the command line, {@code false} if they must follow End of Options.
*/
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add @since 4.8.0 to the javadoc for all public methods that were added in this pull request?

(Picocli follows semantic versioning, so additional API means the next version number should be 4.8.0, not 4.7.6.)

@remkop remkop added type: enhancement ✨ type: API 🔌 theme: parser An issue or change related to the parser labels Dec 14, 2023
@ddsharpe
Copy link
Author

Just a side note, I think these files might need to be cleaned up. It looks like you accidentally pushed CRLF (or GIT failed to remove the CR during the push).
docs/A-Whirlwind-Tour-of-Picocli.html
docs/announcing-picocli-1.0.html
docs/autocomplete.html
docs/build-great-native-cli-apps-in-java-with-graalvm-and-picocli.html
docs/feedback.html
docs/groovy-2.5-clibuilder-renewal-part1.html
docs/groovy-2.5-clibuilder-renewal-part2.html
docs/groovy-2.5-clibuilder-renewal.html
docs/index.html
docs/man/index.html
docs/migrating-from-commons-cli.html
docs/picocli-2.0-do-more-with-less.html
docs/picocli-2.0-groovy-scripts-on-steroids.html
docs/picocli-on-graalvm.html
docs/picocli-programmatic-api.html
docs/quick-guide.html
docs/zh/picocli-2.0-do-more-with-less.html
docs/zh/picocli-2.0-groovy-scripts-on-steroids.html

@remkop
Copy link
Owner

remkop commented Dec 20, 2023

Just a side note, I think these files might need to be cleaned up. It looks like you accidentally pushed CRLF (or GIT failed to remove the CR during the push). docs/A-Whirlwind-Tour-of-Picocli.html docs/announcing-picocli-1.0.html docs/autocomplete.html docs/build-great-native-cli-apps-in-java-with-graalvm-and-picocli.html docs/feedback.html docs/groovy-2.5-clibuilder-renewal-part1.html docs/groovy-2.5-clibuilder-renewal-part2.html docs/groovy-2.5-clibuilder-renewal.html docs/index.html docs/man/index.html docs/migrating-from-commons-cli.html docs/picocli-2.0-do-more-with-less.html docs/picocli-2.0-groovy-scripts-on-steroids.html docs/picocli-on-graalvm.html docs/picocli-programmatic-api.html docs/quick-guide.html docs/zh/picocli-2.0-do-more-with-less.html docs/zh/picocli-2.0-groovy-scripts-on-steroids.html

It is possible that what you are seeing is related to this recent change: #2174
(which ironically was meant to fix CRLF issues...)

@ddsharpe
Copy link
Author

when editing the documentation, so I need to modify both index.adoc and index.html?

@remkop
Copy link
Owner

remkop commented Dec 21, 2023

No, there’s no need to change the HTML, those are generated from the AsciiDoc.
Just the AsciiDoc is fine.

@ddsharpe
Copy link
Author

ddsharpe commented Jan 4, 2024

Requested changes complete. Please re-review.

@remkop
Copy link
Owner

remkop commented Jan 4, 2024

Thank you!
Still reviewing, but looks good so far.

Note that I’ll probably do one more 4.7.x release before merging this PR into the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser type: API 🔌 type: enhancement ✨
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force parameters to follow options
2 participants