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

SOLR-17442: Resolve -v flag conflict (version, value, verbose) #2721

Merged
merged 17 commits into from
Sep 28, 2024

Conversation

epugh
Copy link
Contributor

@epugh epugh commented Sep 23, 2024

https://issues.apache.org/jira/browse/SOLR-17442

Description

Deprecating -v in favour of -d.

Solution

Please provide a short description of the approach taken to implement your solution.

Tests

Please describe the tests you've developed or run to confirm this patch implements the feature or solves the problem.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

Copy link
Contributor

@malliaridis malliaridis left a comment

Choose a reason for hiding this comment

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

I forgot to mention in the ticket that introducing -d for debug may require further deprecations where -d is used for other options as well.

@@ -148,9 +154,21 @@ public class SolrCLI implements CLIO {
public static final Option OPTION_VERBOSE =
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we mark deprecated options with @Deprecated? If so, this would be beneficial for OPTION_VERBOSE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey, I hadn't thought about that use.... Good catch, and we should.

Comment on lines 140 to 145
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.7")
.setDescription("Use --solr-url instead")
.get())
Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving this as a note: Splitting url from solr-url would have a way too large impact in the rest of the tools, so simply marking both as deprecated is a good tradeoff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interesting, I actually don't know why I added this... It doesn't seem to fit the rest of this PR...

Comment on lines 329 to 330
if (!cli.hasOption((SolrCLI.OPTION_DEBUG.getOpt()))
|| cli.hasOption(SolrCLI.OPTION_VERBOSE.getOpt())) {
Copy link
Contributor

@malliaridis malliaridis Sep 24, 2024

Choose a reason for hiding this comment

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

By putting both options (verbose and debug) into an OptionGroup, this can be simplified as well.

Comment on lines 166 to 171
public static final Option OPTION_DEBUG =
Option.builder("d")
.longOpt("debug")
.required(false)
.desc("Enable additional command output.")
.build();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure if we would go for the --debug option. Shall we also deprecate the -d for all the other arguments as well in this PR? We use -d in quite a few places and providing the -d now for debug to all tools may cause unexpected behavior.

@epugh
Copy link
Contributor Author

epugh commented Sep 24, 2024

I forgot to mention in the ticket that introducing -d for debug may require further deprecations where -d is used for other options as well.

I am wondering if we should just stick to --debug, I saw a -d for directory... it's not a common command to run, so maybe having a short cut isn't that valuable.... And dealing with the -d, well that seems really tough....

@epugh
Copy link
Contributor Author

epugh commented Sep 24, 2024

I forgot to mention in the ticket that introducing -d for debug may require further deprecations where -d is used for other options as well.

I am wondering if we should just stick to --debug, I saw a -d for directory... it's not a common command to run, so maybe having a short cut isn't that valuable.... And dealing with the -d, well that seems really tough....

I checked what Docker does, just for run, and they use -D:

-D, --debug              Enable debug mode

I am kind of leaning towards avoiding the whole -d topic by removing it

@malliaridis
Copy link
Contributor

-d is one of the conflicting flags that we have to resolve anyway. I would prefer only the long variant in that case, which may be either debug or verbose, both are fine and when the user uses either of them he is already comitted to be more explicit with the CLI, if that makes sense.

@github-actions github-actions bot added documentation Improvements or additions to documentation start-scripts labels Sep 25, 2024
Copy link
Contributor

@malliaridis malliaridis left a comment

Choose a reason for hiding this comment

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

I think we should start sooner using OptionGroups. I realized in this review and after testing it that we could simplify a lot of logic with them.

Many comments but mostly minor or repetitive things.

solr/bin/solr.cmd Outdated Show resolved Hide resolved
solr/bin/solr.cmd Outdated Show resolved Hide resolved
solr/bin/solr Outdated Show resolved Hide resolved
solr/bin/solr Outdated Show resolved Hide resolved
Comment on lines 134 to 136
debug =
cli.hasOption((SolrCLI.OPTION_DEBUG.getOpt()))
|| cli.hasOption(SolrCLI.OPTION_VERBOSE.getOpt());
Copy link
Contributor

Choose a reason for hiding this comment

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

With an OptionGroup this could be simplified to debug = cli.hasOption(SolrCLI.OPTION_DEBUG), where SolrCLI.OPTION_DEBUG is the OptionGroup that includes verbose and debug options.

Note that the help outputs may be different if using option groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I need to dig more in and write a unit test to prove that works!

Comment on lines 366 to 367
if (cli.hasOption((SolrCLI.OPTION_DEBUG.getOpt()))
|| cli.hasOption(SolrCLI.OPTION_VERBOSE.getOpt())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

... and here (OptionGroup).

print("such as: ./solr start --help or ./solr stop -h");
print("Global Options:");
print(" -v, --version Print version information and quit");
print(" -d, --debug Enable debug mode");
Copy link
Contributor

Choose a reason for hiding this comment

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

-d should probably not included here.

Comment on lines 50 to 51
cli.hasOption((SolrCLI.OPTION_DEBUG.getOpt()))
|| cli.hasOption(SolrCLI.OPTION_VERBOSE.getOpt());
Copy link
Contributor

Choose a reason for hiding this comment

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

OptionGroup simplification.

Comment on lines 37 to 38
if (cli.hasOption((SolrCLI.OPTION_DEBUG.getOpt()))
|| cli.hasOption(SolrCLI.OPTION_VERBOSE.getOpt())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

OptionGroup simplification.

solr/packaging/test/test_bats.bats Outdated Show resolved Hide resolved
@epugh
Copy link
Contributor Author

epugh commented Sep 28, 2024

@malliaridis I was able to integrate OptionGroup for the --debug and --verbose options in this PR and it works. What I haven't been able to grok is how to simplify the checking for the flags. You still have to check for each it apepars!! If you find some code that avoids that, let me know.

I am going to open a fresh PR that uses optiongroups more widely.

@epugh
Copy link
Contributor Author

epugh commented Sep 28, 2024

I was at the point of merging and the --debug syntax just bugged me. I am backing it out and just keep --verbose which rings better for me, and still accomplishs the goal of making -v no longer overlap.

@malliaridis
Copy link
Contributor

malliaridis commented Sep 28, 2024

You still have to check for each it apepars!! If you find some code that avoids that, let me know.

I see that you are using the Option#getOpt() and Option#getLongOpt() when you use CommandLine#getOptionValue(String option) or CommandLine#hasOption(String option).

There is also a CommandLine#getOptionValue(Option option) and CommandLine#getOptionValue(OptionGroup optionGroup) that you could use instead. Same applies for hasOption. That way it is possible to use the OptionGroup and simplify logic as proposed before.

You can also set things like required (exactly one of the options in the group is present) at the OptionGroup via OptionGroup#setRequired(boolean required). This is useful for cases where required options are split intot two due to deprecation, made optional and checked later for presence explicitly, like in ConfigTool.java:

Option.builder("v")
    .longOpt("value")
    .deprecated(...)
    .required(false)
    //...
Option.builder()
    .longOpt("value")
    .required(false) // should be true when -v is removed.
    //...

String value = SolrCLI.getOptionWithDeprecatedAndDefault(cli, "value", "v", null);
//...
if (value == null) {
    throw new MissingArgumentException("'value' is a required option.");
}

Using OptionGroups in a wider range like you started in the other PR will probably render SolrCLI#getOptionWithDeprecatedAndDefault(...) obsolete.

@epugh epugh merged commit eda5ec3 into apache:main Sep 28, 2024
4 of 5 checks passed
epugh added a commit that referenced this pull request Sep 28, 2024
Deprecate the various uses of -v, so that we don't have conflicts there.

---------

Signed-off-by: Eric Pugh <[email protected]>
(cherry picked from commit eda5ec3)
Comment on lines +152 to +157
.deprecated(
DeprecatedAttributes.builder()
.setForRemoval(true)
.setSince("9.8")
.setDescription("Use --debug instead")
.get())
Copy link
Contributor

Choose a reason for hiding this comment

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

@epugh could you review this file again? I think this should be undone if we won't introduce --debug and deprecate -v for version (below too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:cli documentation Improvements or additions to documentation start-scripts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants