Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17357: Improve SolrCLI tool --help printout (#2545)

Jan Høydahlf3f441c5300c
diff --git a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
index d9fc740ddcd..8a6163f0945 100644
--- a/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
+++ b/solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
@@ -320,10 +320,7 @@ public class RunExampleTool extends ToolBase {
"--solr-url", solrUrl
};
CreateTool createTool = new CreateTool(stdout);
- int createCode =
- createTool.runTool(
- SolrCLI.processCommandLineArgs(
- createTool.getName(), createTool.getOptions(), createArgs));
+ int createCode = createTool.runTool(SolrCLI.processCommandLineArgs(createTool, createArgs));
if (createCode != 0)
throw new Exception(
"Failed to create " + collectionName + " using command: " + Arrays.asList(createArgs));
@@ -353,8 +350,7 @@ public class RunExampleTool extends ToolBase {
exampledocsDir.getAbsolutePath() + "/*.xml"
};
PostTool postTool = new PostTool();
- CommandLine postToolCli =
- SolrCLI.parseCmdLine(postTool.getName(), args, postTool.getOptions());
+ CommandLine postToolCli = SolrCLI.parseCmdLine(postTool, args);
postTool.runTool(postToolCli);
} else {
@@ -435,8 +431,7 @@ public class RunExampleTool extends ToolBase {
filmsJsonFile.getAbsolutePath()
};
PostTool postTool = new PostTool();
- CommandLine postToolCli =
- SolrCLI.parseCmdLine(postTool.getName(), args, postTool.getOptions());
+ CommandLine postToolCli = SolrCLI.parseCmdLine(postTool, args);
postTool.runTool(postToolCli);
} catch (Exception ex) {
@@ -875,10 +870,7 @@ public class RunExampleTool extends ToolBase {
};
CreateTool createTool = new CreateTool(stdout);
- int createCode =
- createTool.runTool(
- SolrCLI.processCommandLineArgs(
- createTool.getName(), createTool.getOptions(), createArgs));
+ int createCode = createTool.runTool(SolrCLI.processCommandLineArgs(createTool, createArgs));
if (createCode != 0)
throw new Exception(
diff --git a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
index 06e0714b722..8463c1529e1 100755
--- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java
@@ -205,7 +205,7 @@ public class SolrCLI implements CLIO {
CLIO.err(iae.getMessage());
System.exit(1);
}
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
System.exit(tool.runTool(cli));
}
@@ -214,7 +214,7 @@ public class SolrCLI implements CLIO {
return newTool(toolType);
}
- public static CommandLine parseCmdLine(String toolName, String[] args, List<Option> toolOptions) {
+ public static CommandLine parseCmdLine(Tool tool, String[] args) {
// the parser doesn't like -D props
List<String> toolArgList = new ArrayList<>();
List<String> dashDList = new ArrayList<>();
@@ -229,7 +229,7 @@ public class SolrCLI implements CLIO {
String[] toolArgs = toolArgList.toArray(new String[0]);
// process command-line args to configure this application
- CommandLine cli = processCommandLineArgs(toolName, toolOptions, toolArgs);
+ CommandLine cli = processCommandLineArgs(tool, toolArgs);
List<String> argList = cli.getArgList();
argList.addAll(dashDList);
@@ -319,20 +319,24 @@ public class SolrCLI implements CLIO {
throw new IllegalArgumentException(toolType + " is not a valid command!");
}
+ /** Returns tool options for given tool, for usage display purposes. Hides deprecated options. */
public static Options getToolOptions(Tool tool) {
Options options = new Options();
options.addOption(OPTION_HELP);
options.addOption(OPTION_VERBOSE);
List<Option> toolOpts = tool.getOptions();
for (Option toolOpt : toolOpts) {
- options.addOption(toolOpt);
+ if (!toolOpt.isDeprecated()) {
+ options.addOption(toolOpt);
+ }
}
return options;
}
/** Parses the command-line arguments passed by the user. */
- public static CommandLine processCommandLineArgs(
- String toolName, List<Option> customOptions, String[] args) {
+ public static CommandLine processCommandLineArgs(Tool tool, String[] args) {
+ List<Option> customOptions = tool.getOptions();
+ String toolName = tool.getName();
Options options = new Options();
options.addOption(OPTION_HELP);
@@ -359,24 +363,37 @@ public class SolrCLI implements CLIO {
}
}
if (!hasHelpArg) {
- CLIO.err("Failed to parse command-line arguments due to: " + exp.getMessage());
+ CLIO.err("Failed to parse command-line arguments due to: " + exp.getMessage() + "\n");
+ printToolHelp(tool);
exit(1);
} else {
- HelpFormatter formatter = HelpFormatter.builder().setShowDeprecated(true).get();
- formatter.printHelp(toolName, options);
+ printToolHelp(tool);
exit(0);
}
}
if (cli.hasOption("help")) {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp(toolName, options);
+ printToolHelp(tool);
exit(0);
}
return cli;
}
+ /** Prints tool help for a given tool */
+ private static void printToolHelp(Tool tool) {
+ HelpFormatter formatter = HelpFormatter.builder().get();
+ formatter.setWidth(120);
+ Options optionsNoDeprecated = new Options();
+ tool.getOptions().stream()
+ .filter(option -> !option.isDeprecated())
+ .forEach(optionsNoDeprecated::addOption);
+ String usageString = tool.getUsage() == null ? "bin/solr " + tool.getName() : tool.getUsage();
+ boolean autoGenerateUsage = tool.getUsage() == null;
+ formatter.printHelp(
+ usageString, tool.getHeader(), optionsNoDeprecated, tool.getFooter(), autoGenerateUsage);
+ }
+
/** Scans Jar files on the classpath for Tool implementations to activate. */
private static List<Class<? extends Tool>> findToolClassesInPackage(String packageName) {
List<Class<? extends Tool>> toolClasses = new ArrayList<>();
diff --git a/solr/core/src/java/org/apache/solr/cli/Tool.java b/solr/core/src/java/org/apache/solr/cli/Tool.java
index 120eac2a9a1..aec76be8083 100644
--- a/solr/core/src/java/org/apache/solr/cli/Tool.java
+++ b/solr/core/src/java/org/apache/solr/cli/Tool.java
@@ -25,6 +25,31 @@ public interface Tool {
/** Defines the interface to a Solr tool that can be run from this command-line app. */
String getName();
+ /**
+ * Provides a Usage string to display in help output. Defaults to auto generating usage string.
+ * Override for custom string
+ *
+ * @return The custom usage string or 'null' to auto generate (default)
+ */
+ default String getUsage() {
+ return null;
+ }
+
+ /**
+ * Optional header to display before the options in help output. Defaults to 'List of options:'
+ */
+ default String getHeader() {
+ return "\nList of options:";
+ }
+
+ /**
+ * Optional footer to display after the options in help output. Defaults to a link to reference
+ * guide
+ */
+ default String getFooter() {
+ return "\nPlease see the Reference Guide for more tools documentation: https://solr.apache.org/guide/solr/latest/deployment-guide/solr-control-script-reference.html";
+ }
+
List<Option> getOptions();
int runTool(CommandLine cli) throws Exception;
diff --git a/solr/core/src/test/org/apache/solr/cli/AuthToolTest.java b/solr/core/src/test/org/apache/solr/cli/AuthToolTest.java
index a91a4577ba6..60f5271c12f 100644
--- a/solr/core/src/test/org/apache/solr/cli/AuthToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/AuthToolTest.java
@@ -81,7 +81,7 @@ public class AuthToolTest extends SolrCloudTestCase {
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof AuthTool);
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
}
diff --git a/solr/core/src/test/org/apache/solr/cli/CreateToolTest.java b/solr/core/src/test/org/apache/solr/cli/CreateToolTest.java
index e0ee7807533..333b541f7e6 100644
--- a/solr/core/src/test/org/apache/solr/cli/CreateToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/CreateToolTest.java
@@ -60,7 +60,7 @@ public class CreateToolTest extends SolrCloudTestCase {
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof CreateTool);
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
}
diff --git a/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java b/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java
index 59e1d6a7fe2..535ffc75573 100644
--- a/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/DeleteToolTest.java
@@ -97,7 +97,7 @@ public class DeleteToolTest extends SolrCloudTestCase {
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof DeleteTool);
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
}
diff --git a/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java b/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java
index 088346aa383..a0f3263207d 100644
--- a/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/HealthcheckToolTest.java
@@ -80,7 +80,7 @@ public class HealthcheckToolTest extends SolrCloudTestCase {
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof HealthcheckTool);
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
}
diff --git a/solr/core/src/test/org/apache/solr/cli/PackageToolTest.java b/solr/core/src/test/org/apache/solr/cli/PackageToolTest.java
index 7a6774017f2..e84a853f751 100644
--- a/solr/core/src/test/org/apache/solr/cli/PackageToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/PackageToolTest.java
@@ -374,7 +374,7 @@ public class PackageToolTest extends SolrCloudTestCase {
}
private void run(PackageTool tool, String[] args) throws Exception {
- int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("Non-zero status returned for: " + Arrays.toString(args), 0, res);
}
diff --git a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
index 98686c277e2..862c48363de 100644
--- a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
@@ -150,7 +150,7 @@ public class PostToolTest extends SolrCloudTestCase {
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof PostTool);
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
diff --git a/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java b/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java
index 747b78dc8ba..3da316a1702 100644
--- a/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java
@@ -91,7 +91,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
ConfigSetUploadTool tool = new ConfigSetUploadTool();
- int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("tool should have returned 0 for success ", 0, res);
// Now do we have that config up on ZK?
verifyZkLocalPathsMatch(srcPathCheck, "/configs/upconfig2");
@@ -99,7 +99,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
// do we barf on a bogus path?
args = new String[] {"--conf-name", "upconfig3", "--conf-dir", "nothinghere", "-z", zkAddr};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertTrue("tool should have returned non-zero for failure ", 0 != res);
String content =
@@ -129,9 +129,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
};
ConfigSetDownloadTool downTool = new ConfigSetDownloadTool();
- int res =
- downTool.runTool(
- SolrCLI.processCommandLineArgs(downTool.getName(), downTool.getOptions(), args));
+ int res = downTool.runTool(SolrCLI.processCommandLineArgs(downTool, args));
assertEquals("Download should have succeeded.", 0, res);
verifyZkLocalPathsMatch(
Paths.get(tmp.toAbsolutePath().toString(), "conf"), "/configs/downconfig1");
@@ -155,9 +153,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- downTool.runTool(
- SolrCLI.processCommandLineArgs(downTool.getName(), downTool.getOptions(), args));
+ res = downTool.runTool(SolrCLI.processCommandLineArgs(downTool, args));
assertEquals("Download should have succeeded.", 0, res);
verifyZkLocalPathsMatch(
Paths.get(tmp.toAbsolutePath().toString(), "conf"), "/configs/downconfig2");
@@ -186,8 +182,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
ZkCpTool cpTool = new ZkCpTool();
- int res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ int res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy from zk -> zk should have succeeded.", 0, res);
verifyZnodesMatch("/configs/cp1", "/cp2");
@@ -205,8 +200,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
verifyZkLocalPathsMatch(tmp, "/configs/cp1");
@@ -224,8 +218,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
verifyZkLocalPathsMatch(tmp, "/configs/cp1");
@@ -242,8 +235,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
verifyZkLocalPathsMatch(srcPathCheck, "/cp3");
@@ -260,8 +252,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
verifyZkLocalPathsMatch(srcPathCheck, "/cp4");
@@ -276,8 +267,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertTrue("Copy should NOT have succeeded, recurse not specified.", 0 != res);
// try with recurse = false
@@ -293,8 +283,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertTrue("Copy should NOT have succeeded, recurse set to false.", 0 != res);
// NOTE: really can't test copying to '.' because the test framework doesn't allow altering the
@@ -315,8 +304,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should nave created intermediate directory locally.", 0, res);
assertTrue(
"File should have been copied to a directory successfully",
@@ -336,8 +324,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy up to intermediate file should have succeeded.", 0, res);
assertTrue(
"Should have created an intermediate node on ZK",
@@ -357,8 +344,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy up to named file should have succeeded.", 0, res);
assertTrue(
"Should NOT have created an intermediate node on ZK",
@@ -381,8 +367,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy to local named file should have succeeded.", 0, res);
Path locPath = Paths.get(localNamed);
assertTrue("Should have found file: " + localNamed, Files.exists(locPath));
@@ -406,8 +391,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy from somewhere in ZK to ZK root should have succeeded.", 0, res);
assertTrue(
"Should have found znode /solrconfig.xml: ", zkClient.exists("/solrconfig.xml", true));
@@ -426,8 +410,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
verifyZkLocalPathsMatch(srcPathCheck, "/cp7/" + srcPathCheck.getFileName().toString());
@@ -450,8 +433,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
String content =
@@ -459,8 +441,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkClient.getData("/cp7/conf/stopwords", null, null, true), StandardCharsets.UTF_8);
assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}"));
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
tmp = createTempDir("cp8");
@@ -475,8 +456,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host",
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
// Next, copy cp7 down and verify that zknode.data exists for cp7
@@ -496,8 +476,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
content =
@@ -521,8 +500,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
Path tmp2 = createTempDir("cp9");
@@ -538,8 +516,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host",
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
assertTrue("Empty files should NOT be copied down as directories", emptyDest.toFile().isFile());
@@ -558,8 +535,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
// Now copy it all back and make sure empty file is still a file when recursively copying.
@@ -575,8 +551,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host",
zkAddr,
};
- res =
- cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool.getName(), cpTool.getOptions(), args));
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(cpTool, args));
assertEquals("Copy should have succeeded.", 0, res);
Path locEmpty = Paths.get(tmp2.toAbsolutePath().toString(), "stopwords", "emptyfile");
@@ -603,8 +578,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
ZkMvTool mvTool = new ZkMvTool();
- int res =
- mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args));
+ int res = mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool, args));
assertEquals("Move should have succeeded.", 0, res);
// Now does the moved directory match the original on disk?
@@ -625,8 +599,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
};
// Still in mv2
- res =
- mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args));
+ res = mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool, args));
assertTrue("Move should NOT have succeeded with file: specified.", 0 != res);
// Let's move it to yet another place with no zk: prefix.
@@ -637,8 +610,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res =
- mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args));
+ res = mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool, args));
assertEquals("Move should have succeeded.", 0, res);
assertFalse("Znode /mv3 really should be gone", zkClient.exists("/mv3", true));
@@ -653,8 +625,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"-z", zkAddr,
};
- res =
- mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args));
+ res = mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool, args));
assertEquals("Move should have succeeded.", 0, res);
assertTrue(
"Should be able to move a single file",
@@ -670,8 +641,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res =
- mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool.getName(), mvTool.getOptions(), args));
+ res = mvTool.runTool(SolrCLI.processCommandLineArgs(mvTool, args));
assertEquals("Move should have succeeded.", 0, res);
assertTrue(
"Should be able to move a single file to a parent znode",
@@ -700,7 +670,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
PrintStream ps = new PrintStream(baos, false, StandardCharsets.UTF_8.name());
ZkLsTool tool = new ZkLsTool(ps);
- int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
String content = baos.toString(StandardCharsets.UTF_8);
assertEquals("List should have succeeded", res, 0);
@@ -715,7 +685,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
assertEquals("List should have succeeded", res, 0);
@@ -730,7 +700,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
assertEquals("List should have succeeded", res, 0);
@@ -745,7 +715,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
assertEquals("List should have succeeded", res, 0);
@@ -757,7 +727,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--path", "/", "--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
assertEquals("List should have succeeded", res, 0);
assertFalse("Return should not contain /zookeeper", content.contains("/zookeeper"));
@@ -770,7 +740,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
content = baos.toString(StandardCharsets.UTF_8);
assertEquals("List should have succeeded", res, 0);
@@ -795,7 +765,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
ZkRmTool tool = new ZkRmTool();
- int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertTrue(
"Should have failed to remove node with children unless -recurse is set to true", res != 0);
@@ -810,7 +780,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertTrue(
"Should have failed to remove node with children if -recurse is set to false", res != 0);
@@ -822,7 +792,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("Should have removed node /configs/rm1", res, 0);
assertFalse(
"Znode /configs/toremove really should be gone", zkClient.exists("/configs/rm1", true));
@@ -835,7 +805,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
"--zk-host", zkAddr,
};
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("Should have removed node /configs/rm2", res, 0);
assertFalse(
"Znode /configs/toremove2 really should be gone", zkClient.exists("/configs/rm2", true));
@@ -849,7 +819,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {
};
AbstractDistribZkTestBase.copyConfigUp(configSet, "cloud-subdirs", "rm3", zkAddr);
- res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertNotEquals("Should fail when trying to remove /.", 0, res);
}
diff --git a/solr/core/src/test/org/apache/solr/cli/TestExportTool.java b/solr/core/src/test/org/apache/solr/cli/TestExportTool.java
index 9ca2a36a6d4..1223925058b 100644
--- a/solr/core/src/test/org/apache/solr/cli/TestExportTool.java
+++ b/solr/core/src/test/org/apache/solr/cli/TestExportTool.java
@@ -261,7 +261,7 @@ public class TestExportTool extends SolrCloudTestCase {
private int runTool(String[] args) throws Exception {
Tool tool = findTool(args);
assertTrue(tool instanceof ExportTool);
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
diff --git a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
index d99cce91099..87b6e0d41ef 100644
--- a/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
+++ b/solr/core/src/test/org/apache/solr/cli/TestSolrCLIRunExample.java
@@ -370,9 +370,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
RunExampleTool tool = new RunExampleTool(executor, System.in, stdoutSim);
try {
- int status =
- tool.runTool(
- SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), toolArgs));
+ int status = tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
if (status == -1) {
// maybe it's the port, try again
@@ -380,9 +378,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
bindPort = socket.getLocalPort();
}
Thread.sleep(100);
- status =
- tool.runTool(
- SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), toolArgs));
+ status = tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
}
assertEquals("it should be ok " + tool + " " + Arrays.toString(toolArgs), 0, status);
@@ -491,7 +487,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
RunExampleTool tool = new RunExampleTool(executor, userInputSim, stdoutSim);
try {
- tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), toolArgs));
+ tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
} catch (Exception e) {
System.err.println(
"RunExampleTool failed due to: "
@@ -555,8 +551,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
// delete the collection
DeleteTool deleteTool = new DeleteTool(stdoutSim);
String[] deleteArgs = new String[] {"--name", collectionName, "--solr-url", solrUrl};
- deleteTool.runTool(
- SolrCLI.processCommandLineArgs(deleteTool.getName(), deleteTool.getOptions(), deleteArgs));
+ deleteTool.runTool(SolrCLI.processCommandLineArgs(deleteTool, deleteArgs));
// dump all the output written by the SolrCLI commands to stdout
// System.out.println(toolOutput);
@@ -602,8 +597,7 @@ public class TestSolrCLIRunExample extends SolrTestCaseJ4 {
DefaultExecutor executor = new DefaultExecutor();
RunExampleTool tool = new RunExampleTool(executor, System.in, stdoutSim);
- int code =
- tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), toolArgs));
+ int code = tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
assertEquals("Execution should have failed with return code 1", 1, code);
}
}
diff --git a/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java b/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java
index f8e24cbcb07..8185c5b1457 100644
--- a/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/ZkSubcommandsTest.java
@@ -694,7 +694,7 @@ public class ZkSubcommandsTest extends SolrTestCaseJ4 {
}
private int runTool(String[] args, Tool tool) throws Exception {
- CommandLine cli = parseCmdLine(tool.getName(), args, tool.getOptions());
+ CommandLine cli = parseCmdLine(tool, args);
return tool.runTool(cli);
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
index 944e5e81272..014de63b8a0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
@@ -91,7 +91,7 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
// no-no in a JUnit test
CreateTool tool = new CreateTool();
- CommandLine cli = SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args);
+ CommandLine cli = SolrCLI.processCommandLineArgs(tool, args);
log.info("Creating the '{}' collection using SolrCLI with: {}", testCollectionName, solrUrl);
tool.runTool(cli);
assertTrue(
@@ -123,8 +123,7 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
};
PostTool postTool = new PostTool();
- CommandLine postCli =
- SolrCLI.processCommandLineArgs(postTool.getName(), postTool.getOptions(), argsForPost);
+ CommandLine postCli = SolrCLI.processCommandLineArgs(postTool, argsForPost);
postTool.runTool(postCli);
int expectedXmlDocCount = 32;
@@ -159,7 +158,7 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
"--zk-host", zkHost
};
HealthcheckTool tool = new HealthcheckTool();
- CommandLine cli = SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args);
+ CommandLine cli = SolrCLI.processCommandLineArgs(tool, args);
assertEquals("Healthcheck action failed!", 0, tool.runTool(cli));
}
@@ -170,7 +169,7 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
"--solr-url", solrUrl
};
DeleteTool tool = new DeleteTool();
- CommandLine cli = SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args);
+ CommandLine cli = SolrCLI.processCommandLineArgs(tool, args);
assertEquals("Delete action failed!", 0, tool.runTool(cli));
assertFalse(
SolrCLI.safeCheckCollectionExists(
diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
index 5c78e5ef9b5..1c960c07e1f 100644
--- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
+++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java
@@ -304,7 +304,7 @@ public class BasicAuthIntegrationTest extends SolrCloudAuthTestCase {
StatusTool tool = new StatusTool(stdoutSim);
try {
System.setProperty("basicauth", "harry:HarryIsUberCool");
- tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), toolArgs));
+ tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
Map<?, ?> obj = (Map<?, ?>) Utils.fromJSON(new ByteArrayInputStream(baos.toByteArray()));
assertTrue(obj.containsKey("version"));
assertTrue(obj.containsKey("startTime"));
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
index 5e0db3135c4..37c90d98db9 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java
@@ -421,7 +421,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
ConfigSetUploadTool tool = new ConfigSetUploadTool();
- int res = tool.runTool(SolrCLI.processCommandLineArgs(tool.getName(), tool.getOptions(), args));
+ int res = tool.runTool(SolrCLI.processCommandLineArgs(tool, args));
assertEquals("Tool should have returned 0 for success, returned: " + res, res, 0);
}
}