You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2022/08/09 08:13:32 UTC
[ignite-3] branch main updated: IGNITE-17348 Added quit/exit command to Ignite3 CLI sql REPL. Fixes #971
This is an automated email from the ASF dual-hosted git repository.
sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 8e25fce53 IGNITE-17348 Added quit/exit command to Ignite3 CLI sql REPL. Fixes #971
8e25fce53 is described below
commit 8e25fce53bcc0079008efaf3fc0bab9da28b96a8
Author: Vadim Pakhnushev <86...@users.noreply.github.com>
AuthorDate: Tue Aug 9 11:06:39 2022 +0300
IGNITE-17348 Added quit/exit command to Ignite3 CLI sql REPL. Fixes #971
Signed-off-by: Slava Koptilin <sl...@gmail.com>
---
.../ignite/cli/commands/sql/SqlReplCommand.java | 8 +++-----
.../core/repl/executor/RegistryCommandExecutor.java | 21 ++++++++++++++++++++-
.../ignite/cli/core/repl/executor/ReplExecutor.java | 5 +++--
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java b/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
index 5f6aa702b..1647916c8 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/commands/sql/SqlReplCommand.java
@@ -48,8 +48,6 @@ import picocli.CommandLine.Parameters;
*/
@Command(name = "sql", description = "Executes SQL query.")
public class SqlReplCommand extends BaseCommand implements Runnable {
- private static final String INTERNAL_COMMAND_PREFIX = "!";
-
@Option(names = {"-u", "--jdbc-url"}, required = true,
descriptionKey = "ignite.jdbc-url", description = "JDBC url to ignite cluster")
private String jdbc;
@@ -100,8 +98,8 @@ public class SqlReplCommand extends BaseCommand implements Runnable {
}
private CallExecutionPipelineProvider provider(SqlManager sqlManager) {
- return (call, exceptionHandlers, line) -> line.startsWith(INTERNAL_COMMAND_PREFIX)
- ? createInternalCommandPipeline(call, exceptionHandlers, line)
+ return (executor, exceptionHandlers, line) -> executor.hasCommand(line)
+ ? createInternalCommandPipeline(executor, exceptionHandlers, line)
: createSqlExecPipeline(sqlManager, line);
}
@@ -118,7 +116,7 @@ public class SqlReplCommand extends BaseCommand implements Runnable {
ExceptionHandlers exceptionHandlers,
String line) {
return CallExecutionPipeline.builder(call)
- .inputProvider(() -> new StringCallInput(line.substring(INTERNAL_COMMAND_PREFIX.length())))
+ .inputProvider(() -> new StringCallInput(line))
.output(spec.commandLine().getOut())
.errOutput(spec.commandLine().getErr())
.exceptionHandlers(exceptionHandlers)
diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/RegistryCommandExecutor.java b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/RegistryCommandExecutor.java
index 5077fde67..e2cd681d6 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/RegistryCommandExecutor.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/RegistryCommandExecutor.java
@@ -23,6 +23,9 @@ import org.apache.ignite.cli.core.call.CallOutput;
import org.apache.ignite.cli.core.call.DefaultCallOutput;
import org.apache.ignite.cli.core.call.StringCallInput;
import org.jline.console.SystemRegistry;
+import org.jline.reader.ParsedLine;
+import org.jline.reader.Parser;
+import org.jline.reader.Parser.ParseContext;
/**
* Command executor based on {@link SystemRegistry}.
@@ -30,13 +33,17 @@ import org.jline.console.SystemRegistry;
public class RegistryCommandExecutor implements Call<StringCallInput, Object> {
private final SystemRegistry systemRegistry;
+ private final Parser parser;
+
/**
* Constructor.
*
* @param systemRegistry {@link SystemRegistry} instance.
+ * @param parser A {@link Parser} used to create {@code systemRegistry}.
*/
- public RegistryCommandExecutor(SystemRegistry systemRegistry) {
+ public RegistryCommandExecutor(SystemRegistry systemRegistry, Parser parser) {
this.systemRegistry = systemRegistry;
+ this.parser = parser;
}
/**
@@ -65,4 +72,16 @@ public class RegistryCommandExecutor implements Call<StringCallInput, Object> {
public void cleanUp() {
systemRegistry.cleanUp();
}
+
+ /**
+ * Determines whether the {@link SystemRegistry} has a command with this name.
+ *
+ * @param line command name to check.
+ * @return true if the registry has the command.
+ */
+ public boolean hasCommand(String line) {
+ ParsedLine pl = parser.parse(line, 0, ParseContext.SPLIT_LINE);
+
+ return !pl.words().isEmpty() && systemRegistry.hasCommand(parser.getCommand(pl.words().get(0)));
+ }
}
diff --git a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java
index 176f004ce..d62d63620 100644
--- a/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java
+++ b/modules/cli/src/main/java/org/apache/ignite/cli/core/repl/executor/ReplExecutor.java
@@ -43,6 +43,7 @@ import org.jline.reader.LineReaderBuilder;
import org.jline.reader.MaskingCallback;
import org.jline.reader.Parser;
import org.jline.reader.impl.DefaultParser;
+import org.jline.reader.impl.completer.AggregateCompleter;
import org.jline.terminal.Terminal;
import org.jline.widget.TailTipWidgets;
import picocli.CommandLine;
@@ -92,13 +93,13 @@ public class ReplExecutor {
registry.register("help", picocliCommands);
LineReader reader = createReader(repl.getCompleter() != null
- ? repl.getCompleter()
+ ? new AggregateCompleter(registry.completer(), repl.getCompleter())
: registry.completer());
if (repl.getHistoryFileName() != null) {
reader.variable(LineReader.HISTORY_FILE, new File(StateFolderProvider.getStateFolder(), repl.getHistoryFileName()));
}
- RegistryCommandExecutor executor = new RegistryCommandExecutor(registry);
+ RegistryCommandExecutor executor = new RegistryCommandExecutor(registry, parser);
if (repl.isTailTipWidgetsEnabled()) {
TailTipWidgets widgets = new TailTipWidgets(reader, registry::commandDescription, 5,
TailTipWidgets.TipType.COMPLETER);