From e194757c00db6698280e45d5e7ba6e391994f054 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 24 Jan 2022 18:20:38 +1100 Subject: [PATCH] Improve terminal help text Fixes #23036 --- .../deployment/console/AeshConsole.java | 7 +++++++ .../deployment/console/ConsoleProcessor.java | 20 +++++++++++++++++++ .../deployment/console/QuarkusCommand.java | 9 ++++++++- .../logging/LoggingResourceProcessor.java | 8 ++++++-- .../deployment/PostgresCommand.java | 7 ++++++- .../console/ConfigEditorProcessor.java | 7 ++++++- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/AeshConsole.java b/core/deployment/src/main/java/io/quarkus/deployment/console/AeshConsole.java index 76825c073ceb7..3eb446e39c04c 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/console/AeshConsole.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/AeshConsole.java @@ -70,6 +70,7 @@ protected Boolean initialValue() { private final StatusLine prompt; private volatile boolean pauseOutput; + private volatile boolean firstConsoleRun = true; private DelegateConnection delegateConnection; private ReadlineConsole aeshConsole; @@ -528,8 +529,14 @@ public void runAeshCli() { pauseOutput = true; delegateConnection = new DelegateConnection(connection); connection.write(ALTERNATE_SCREEN_BUFFER); + if (firstConsoleRun) { + connection.write( + "You are now in Quarkus Terminal. Your app is still running. Use `help` or tab completion to explore, `quit` or `q` to return to your application.\n"); + firstConsoleRun = false; + } AeshCommandRegistryBuilder commandBuilder = AeshCommandRegistryBuilder.builder(); ConsoleCliManager.commands.forEach(commandBuilder::command); + CommandRegistry registry = commandBuilder .create(); Settings settings = SettingsBuilder diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java index e945ece2c642d..a1811e8e6f74a 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java @@ -188,4 +188,24 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command return CommandResult.SUCCESS; } } + + @BuildStep + ConsoleCommandBuildItem helpCommand() { + return new ConsoleCommandBuildItem(new HelpCommand()); + } + + @CommandDefinition(name = "help", description = "Displays the command list", aliases = { "h" }) + public static class HelpCommand implements Command { + + @Override + public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { + commandInvocation.getShell().writeln("The following commands are available, run them with -h for more info:\n"); + for (var c : ConsoleCliManager.commands) { + commandInvocation.getShell().writeln( + c.getParser().getProcessedCommand().name() + "\t" + c.getParser().getProcessedCommand().description()); + } + + return CommandResult.SUCCESS; + } + } } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusCommand.java b/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusCommand.java index bf20745411b88..f49e9b458eed8 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusCommand.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusCommand.java @@ -10,11 +10,18 @@ public abstract class QuarkusCommand implements Command { - @Option(shortName = 'd', hasValue = false) + @Option(shortName = 'd', hasValue = false, description = "Return to the application after the command has run") public boolean done; + @Option(shortName = 'h', hasValue = false, overrideRequired = true) + public boolean help; + @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { + if (help) { + commandInvocation.getShell().write(commandInvocation.getHelpInfo()); + return CommandResult.SUCCESS; + } var result = doExecute(commandInvocation); if (done) { QuarkusConsole.INSTANCE.exitCliMode(); diff --git a/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java index 0cec6529d9bf7..6274bf445f727 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/logging/LoggingResourceProcessor.java @@ -525,6 +525,9 @@ ConsoleCommandBuildItem logConsoleCommand() { @GroupCommandDefinition(name = "log", description = "Logging Commands") public static class LogCommand implements GroupCommand { + @Option(shortName = 'h', hasValue = false, overrideRequired = true) + public boolean help; + @Override public List getCommands() { return List.of(new SetLogLevelCommand()); @@ -532,6 +535,7 @@ public List getCommands() { @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { + commandInvocation.getShell().writeln(commandInvocation.getHelpInfo()); return CommandResult.SUCCESS; } } @@ -539,10 +543,10 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command @CommandDefinition(name = "set-level", description = "Sets the log level for a logger") public static class SetLogLevelCommand extends QuarkusCommand { - @Option(required = true, completer = LoggerCompleter.class) + @Option(required = true, completer = LoggerCompleter.class, description = "The logger to modify") private String logger; - @Option(required = true, completer = LevelCompleter.class) + @Option(required = true, completer = LevelCompleter.class, description = "The log level") private String level; @Override diff --git a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresCommand.java b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresCommand.java index 83b018ce5821d..ce5c83b19fc39 100644 --- a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresCommand.java +++ b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresCommand.java @@ -8,6 +8,7 @@ import org.aesh.command.GroupCommand; import org.aesh.command.GroupCommandDefinition; import org.aesh.command.invocation.CommandInvocation; +import org.aesh.command.option.Option; import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem; @@ -16,6 +17,9 @@ public class PostgresCommand implements GroupCommand { private final DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResultBuildItem; + @Option(shortName = 'h', hasValue = false, overrideRequired = true) + public boolean help; + public PostgresCommand(DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResultBuildItem) { this.devServicesLauncherConfigResultBuildItem = devServicesLauncherConfigResultBuildItem; } @@ -27,6 +31,7 @@ public List getCommands() { @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - return null; + commandInvocation.getShell().writeln(commandInvocation.getHelpInfo()); + return CommandResult.SUCCESS; } } diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java index ed0b3f1b99c5f..8a3c2833e6ad5 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java @@ -27,6 +27,7 @@ import org.aesh.command.completer.OptionCompleter; import org.aesh.command.invocation.CommandInvocation; import org.aesh.command.option.Argument; +import org.aesh.command.option.Option; import org.aesh.command.validator.CommandValidator; import org.aesh.command.validator.CommandValidatorException; @@ -293,11 +294,14 @@ private boolean isSetByDevServices(Optional getCommands() { @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { + commandInvocation.getShell().writeln(commandInvocation.getHelpInfo()); return CommandResult.SUCCESS; } }