Skip to content

Commit

Permalink
Use OptionGroup to manage the port or solr options.
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Nov 6, 2024
1 parent dda50a1 commit f3a88cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 6 additions & 7 deletions solr/core/src/java/org/apache/solr/cli/StatusTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.TimeoutException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.solr.cli.SolrProcessManager.SolrProcess;
import org.apache.solr.client.solrj.SolrClient;
Expand Down Expand Up @@ -93,12 +94,14 @@ public String getName() {

@Override
public Options getOptions() {
OptionGroup optionGroup = new OptionGroup();
optionGroup.addOption(PORT_OPTION);
optionGroup.addOption(CommonCLIOptions.SOLR_URL_OPTION);
return super.getOptions()
.addOption(MAX_WAIT_SECS_OPTION)
.addOption(PORT_OPTION)
.addOption(SHORT_OPTION)
.addOption(CommonCLIOptions.SOLR_URL_OPTION)
.addOption(CommonCLIOptions.CREDENTIALS_OPTION);
.addOption(CommonCLIOptions.CREDENTIALS_OPTION)
.addOptionGroup(optionGroup);
}

@Override
Expand All @@ -108,10 +111,6 @@ public void runImpl(CommandLine cli) throws Exception {
boolean shortFormat = cli.hasOption(SHORT_OPTION);
int maxWaitSecs = cli.getParsedOptionValue(MAX_WAIT_SECS_OPTION, 0);

if (port != null && solrUrl != null) {
throw new IllegalArgumentException("Only one of port or url can be specified");
}

if (solrUrl != null) {
if (!URLUtil.hasScheme(solrUrl)) {
CLIO.err("Invalid URL provided: " + solrUrl);
Expand Down
7 changes: 5 additions & 2 deletions solr/packaging/test/test_status.bats
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ teardown() {
solr stop
}

@test "multiple connection options are prevented" {
run solr status --port ${SOLR_PORT} --solr-url http://localhost:${SOLR_PORT}
assert_output --partial "The option 's' was specified but an option from this group has already been selected: 'p'"
}

@test "status with invalid --solr-url from user" {
solr start
run solr status --solr-url http://invalidhost:${SOLR_PORT}
assert_output --partial "Solr at http://invalidhost:${SOLR_PORT} not online"
solr stop
}

@test "status with --short format" {
Expand Down

0 comments on commit f3a88cb

Please sign in to comment.