Copilot commented on code in PR #4127:
URL: https://github.com/apache/solr/pull/4127#discussion_r2821519271
##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -530,10 +549,24 @@ protected void runCloudExample(CommandLine cli) throws
Exception {
echo("\nWelcome to the SolrCloud example!\n");
- Scanner readInput = prompt ? new Scanner(userInput,
StandardCharsets.UTF_8) : null;
+ Scanner readInput = null;
+ if (usingPromptInputs) {
+ // Create a scanner from the provided prompts
+ String promptsValue = cli.getOptionValue(PROMPT_INPUTS_OPTION);
+ InputStream promptsStream =
+ new
java.io.ByteArrayInputStream(promptsValue.getBytes(StandardCharsets.UTF_8));
Review Comment:
Using `Scanner` with `useDelimiter(",")` will skip empty tokens (e.g.
`a,,b`), so users can’t "accept default" for a prompt in the middle while still
supplying later values. Consider parsing with a CSV-aware parser or `split(",",
-1)` to preserve empty fields so prompt positions stay aligned.
```suggestion
// Preserve empty fields so that users can "accept default" for a
prompt
// while still providing values for later prompts.
String[] promptTokens = promptsValue.split(",", -1);
for (int i = 0; i < promptTokens.length; i++) {
if (promptTokens[i].isEmpty()) {
// Use a single space so that Scanner produces a token, which the
// prompting logic can then trim() back to an empty string.
promptTokens[i] = " ";
}
}
String processedPromptsValue = String.join(",", promptTokens);
InputStream promptsStream =
new java.io.ByteArrayInputStream(
processedPromptsValue.getBytes(StandardCharsets.UTF_8));
```
##########
solr/solr-ref-guide/modules/deployment-guide/pages/solr-control-script-reference.adoc:
##########
@@ -277,6 +242,56 @@ To emphasize how the default settings work take a moment
to understand that the
`bin/solr start --host localhost -p 8983 --server-dir server --solr-home solr
-m 512m`
+`-e <name>` or `--example <name>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: none
+|===
++
+Start Solr with an example configuration.
+These examples are provided to help you get started faster with Solr
generally, or just try a specific feature.
++
+The available options are:
+
+* `cloud`: SolrCloud example
+* `techproducts`: Comprehensive example illustrating many of Solr's core
capabilities
+* `schemaless`: Schema-less example (schema is inferred from data during
indexing)
+* `films`: Example of starting with _default configset and adding explicit
fields dynamically
++
+See the section <<Running with Example Configurations>> below for more details
on the example configurations.
++
+*Example*: `bin/solr start -e schemaless`
+
+`--no-prompt`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: none
+|===
++
+Don't prompt for input; accept all defaults when running examples that accept
user input.
++
+For example, when using the "cloud" example, an interactive session guides you
through several options for your SolrCloud cluster.
+If you want to accept all of the defaults, you can simply add the
`--no-prompt` option to your request.
++
+*Example*: `bin/solr start -e cloud --no-prompt`
+
+`--prompt-inputs <values>`::
++
+[%autowidth,frame=none]
+|===
+|Optional |Default: none
+|===
++
+Don't prompt for input; provide defaults in comma delimited format when
running examples that accept user input.
++
+For example, when using the "cloud" example, start a three node cluster on
specific ports:
Review Comment:
The `--prompt-inputs` description says "provide defaults", but this option
is actually supplying ordered *answers* to prompts (possibly overriding
defaults). Rewording this line would make the behavior clearer.
```suggestion
Don't prompt for input; instead supply ordered answers in comma-delimited
format when running examples that accept user input. These answers may override
the interactive defaults.
+
For example, when using the "cloud" example, you can answer the prompts
non-interactively to start a three node cluster on specific ports:
```
##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -73,6 +73,16 @@ public class RunExampleTool extends ToolBase {
"Don't prompt for input; accept all defaults when running
examples that accept user input.")
.build();
+ private static final Option PROMPT_INPUTS_OPTION =
+ Option.builder()
+ .longOpt("prompt-inputs")
+ .hasArg()
+ .argName("VALUES")
Review Comment:
The PR title/description refer to `--prompts` / `--prompt=...`, but the
implementation introduces `--prompt-inputs`. Please align on a single flag name
across code, scripts, docs, tests, and changelog to avoid user confusion and
backport pain.
##########
solr/core/src/java/org/apache/solr/cli/RunExampleTool.java:
##########
@@ -530,10 +549,24 @@ protected void runCloudExample(CommandLine cli) throws
Exception {
echo("\nWelcome to the SolrCloud example!\n");
- Scanner readInput = prompt ? new Scanner(userInput,
StandardCharsets.UTF_8) : null;
+ Scanner readInput = null;
+ if (usingPromptInputs) {
+ // Create a scanner from the provided prompts
+ String promptsValue = cli.getOptionValue(PROMPT_INPUTS_OPTION);
+ InputStream promptsStream =
+ new
java.io.ByteArrayInputStream(promptsValue.getBytes(StandardCharsets.UTF_8));
+ readInput = new Scanner(promptsStream, StandardCharsets.UTF_8);
+ readInput.useDelimiter(",");
+ prompt = true; // Enable prompting code path, but reading from prompts
instead of user
+ } else if (prompt) {
+ readInput = new Scanner(userInput, StandardCharsets.UTF_8);
+ }
Review Comment:
When `--prompt-inputs` is used, the code enables the interactive prompting
path (`prompt = true`) but reads from a finite token list. If a provided port
is unavailable (or an input fails validation), the existing retry loops will
consume subsequent tokens as “retries”, shifting the remaining answers (e.g.,
node2 port becomes node1 retry) and leading to unexpected configuration.
Consider failing fast with a clear error when `usingPromptInputs` is true and a
provided value is invalid/unusable, rather than reprompting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]