From 418bd0e7214089cdd0c3d00921120bb9d23ee333 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 6 Jul 2023 14:15:12 -0400 Subject: [PATCH 1/4] remove now dead lines of code --- solr/bin/solr | 20 +------------------- solr/bin/solr.cmd | 22 ---------------------- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/solr/bin/solr b/solr/bin/solr index b5f06d1ecf5..c0bcf545b83 100644 --- a/solr/bin/solr +++ b/solr/bin/solr @@ -339,25 +339,7 @@ function print_usage() { echo -e "\nERROR: $ERROR_MSG\n" fi - if [ -z "${CMD:-}" ]; then - echo "" - echo "Usage: solr COMMAND OPTIONS" - echo " where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, export, api, package" - echo "" - echo " Standalone server example (start Solr running in the background on port 8984):" - echo "" - echo " ./solr start -p 8984" - echo "" - echo " SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled):" - echo "" - echo " ./solr start -c -m 1g -z localhost:2181 -a \"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044\"" - echo "" - echo " Omit '-z localhost:2181' from the above command if you have defined ZK_HOST in solr.in.sh." - echo "" - echo "Pass -help or -h after any COMMAND to see command-specific usage information," - echo " such as: ./solr start -help or ./solr stop -h" - echo "" - elif [[ "$CMD" == "start" || "$CMD" == "restart" ]]; then + if [[ "$CMD" == "start" || "$CMD" == "restart" ]]; then echo "" echo "Usage: solr $CMD [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-t solr.data.home] [-a \"additional-options\"] [-V]" echo "" diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 5f83a2c95db..76835d3a31b 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -282,26 +282,6 @@ IF "%SCRIPT_CMD%"=="auth" goto auth_usage IF "%SCRIPT_CMD%"=="status" goto run_solrcli goto done -:script_usage -@echo. -@echo Usage: solr COMMAND OPTIONS -@echo where COMMAND is one of: start, stop, restart, status, healthcheck, create, create_core, create_collection, delete, version, zk, auth, assert, config, export, api, package -@echo. -@echo Standalone server example (start Solr running in the background on port 8984): -@echo. -@echo solr start -p 8984 -@echo. -@echo SolrCloud example (start Solr running in SolrCloud mode using localhost:2181 to connect to Zookeeper, with 1g max heap size and remote Java debug options enabled): -@echo. -@echo solr start -c -m 1g -z localhost:2181 -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044" -@echo. -@echo Omit '-z localhost:2181' from the above command if you have defined ZK_HOST in solr.in.cmd. -@echo. -@echo Pass -help after any COMMAND to see command-specific usage information, -@echo such as: solr start -help or solr stop -help -@echo. -goto done - :start_usage @echo. @echo Usage: solr %SCRIPT_CMD% [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-t solr.data.home] [-a "additional-options"] [-V] @@ -1664,8 +1644,6 @@ IF "%FIRST_ARG%"=="start" ( goto auth_usage ) ELSE IF "%FIRST_ARG%"=="status" ( goto run_solrcli -) ELSE ( - goto script_usage ) :need_java_home From 733e4352fc6800f3ee99a355749748e59920ad83 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Sat, 8 Jul 2023 12:02:38 -0400 Subject: [PATCH 2/4] handle usage command --- solr/bin/solr.cmd | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd index 76835d3a31b..93f39a39cb2 100755 --- a/solr/bin/solr.cmd +++ b/solr/bin/solr.cmd @@ -223,11 +223,11 @@ set FIRST_ARG=%1 IF [%1]==[] goto usage -IF "%1"=="-help" goto usage -IF "%1"=="-usage" goto usage -IF "%1"=="-h" goto usage -IF "%1"=="--help" goto usage -IF "%1"=="/?" goto usage +IF "%1"=="-help" goto run_solrcli +IF "%1"=="-usage" goto run_solrcli +IF "%1"=="-h" goto run_solrcli +IF "%1"=="--help" goto run_solrcli +IF "%1"=="/?" goto run_solrcli IF "%1"=="status" goto get_status IF "%1"=="version" goto get_version IF "%1"=="-v" goto get_version @@ -263,12 +263,12 @@ goto parse_args :usage IF NOT "%SCRIPT_ERROR%"=="" ECHO %SCRIPT_ERROR% -IF [%FIRST_ARG%]==[] goto script_usage -IF "%FIRST_ARG%"=="-help" goto script_usage -IF "%FIRST_ARG%"=="-usage" goto script_usage -IF "%FIRST_ARG%"=="-h" goto script_usage -IF "%FIRST_ARG%"=="--help" goto script_usage -IF "%FIRST_ARG%"=="/?" goto script_usage +IF [%FIRST_ARG%]==[] goto run_solrcli +IF "%FIRST_ARG%"=="-help" goto run_solrcli +IF "%FIRST_ARG%"=="-usage" goto run_solrcli +IF "%FIRST_ARG%"=="-h" goto run_solrcli +IF "%FIRST_ARG%"=="--help" goto run_solrcli +IF "%FIRST_ARG%"=="/?" goto run_solrcli IF "%SCRIPT_CMD%"=="start" goto start_usage IF "%SCRIPT_CMD%"=="restart" goto start_usage IF "%SCRIPT_CMD%"=="stop" goto stop_usage From d7e55655a40c131bcb9092f70bdbe325c0d435d4 Mon Sep 17 00:00:00 2001 From: Willdotwhite Date: Sun, 16 Jul 2023 19:15:57 +0100 Subject: [PATCH 3/4] Support help flags in SolrCLI --- solr/core/src/java/org/apache/solr/cli/SolrCLI.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 518bfb93039..aa2715d6edf 100755 --- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java @@ -121,7 +121,10 @@ public static void exit(int exitStatus) { /** Runs a tool. */ public static void main(String[] args) throws Exception { - if (args == null || args.length == 0 || args[0] == null || args[0].trim().length() == 0) { + final boolean hasNoCommand = args == null || args.length == 0 || args[0] == null || args[0].trim().length() == 0; + final boolean isHelpCommand = Arrays.asList("-h", "--help", "/?").contains(args[0]); + + if (hasNoCommand || isHelpCommand) { printHelp(); exit(1); } From 729b98cf6d3158c8a6f4767c6b1ce765097d54e6 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Fri, 21 Jul 2023 10:25:52 -0400 Subject: [PATCH 4/4] fix checking logic to avoid NPE --- solr/core/src/java/org/apache/solr/cli/SolrCLI.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 e4ff3a969e3..c7eff7622d1 100755 --- a/solr/core/src/java/org/apache/solr/cli/SolrCLI.java +++ b/solr/core/src/java/org/apache/solr/cli/SolrCLI.java @@ -120,8 +120,10 @@ public static void exit(int exitStatus) { /** Runs a tool. */ public static void main(String[] args) throws Exception { - final boolean hasNoCommand = args == null || args.length == 0 || args[0] == null || args[0].trim().length() == 0; - final boolean isHelpCommand = Arrays.asList("-h", "--help", "/?").contains(args[0]); + final boolean hasNoCommand = + args == null || args.length == 0 || args[0] == null || args[0].trim().length() == 0; + final boolean isHelpCommand = + !hasNoCommand && Arrays.asList("-h", "--help", "/?").contains(args[0]); if (hasNoCommand || isHelpCommand) { printHelp();