diff --git a/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusGroupCommand.java b/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusGroupCommand.java new file mode 100644 index 0000000000000..5de1386b87b72 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/console/QuarkusGroupCommand.java @@ -0,0 +1,20 @@ +package io.quarkus.deployment.console; + +import org.aesh.command.CommandException; +import org.aesh.command.CommandResult; +import org.aesh.command.GroupCommand; +import org.aesh.command.invocation.CommandInvocation; +import org.aesh.command.option.Option; + +public abstract class QuarkusGroupCommand implements GroupCommand { + + @Option(shortName = 'h', hasValue = false, overrideRequired = true) + public boolean help; + + @Override + public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { + commandInvocation.getShell().write(commandInvocation.getHelpInfo()); + return CommandResult.SUCCESS; + } + +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestTracingProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestTracingProcessor.java index 27f21d8104ab8..24becbef9f069 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestTracingProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestTracingProcessor.java @@ -8,6 +8,7 @@ import java.util.Set; import java.util.function.BiFunction; +import io.quarkus.deployment.console.QuarkusGroupCommand; import org.aesh.command.Command; import org.aesh.command.CommandDefinition; import org.aesh.command.CommandException; @@ -197,24 +198,24 @@ ConsoleCommandBuildItem testConsoleCommand(CombinedIndexBuildItem indexBuildItem return new ConsoleCommandBuildItem(new TestCommand()); } - @GroupCommandDefinition(name = "test", description = "Test Commands", groupCommands = { TagsCommand.class, - PatternCommand.class }) - public static class TestCommand implements Command { + @GroupCommandDefinition(name = "test", description = "Test Commands") + public static class TestCommand extends QuarkusGroupCommand { @Override - public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - return CommandResult.SUCCESS; + public List getCommands() { + return List.of(new TagsCommand(), new PatternCommand()); } + } - @GroupCommandDefinition(name = "tags", description = "Tag Commands", groupCommands = { IncludeTagsCommand.class, - ExcludeTagsCommand.class }) - public static class TagsCommand implements Command { + @GroupCommandDefinition(name = "tags", description = "Tag Commands") + public static class TagsCommand extends QuarkusGroupCommand { @Override - public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - return CommandResult.SUCCESS; + public List getCommands() { + return List.of(new IncludeTagsCommand(), new ExcludeTagsCommand()); } + } @CommandDefinition(name = "include", description = "Sets the current included tags") @@ -269,15 +270,14 @@ protected void configure(TestSupport testSupport) { } } - @GroupCommandDefinition(name = "pattern", description = "Include/Exclude pattern Commands", groupCommands = { - IncludePatternCommand.class, - ExcludePatternCommand.class }) - public static class PatternCommand implements Command { + @GroupCommandDefinition(name = "pattern", description = "Include/Exclude pattern Commands") + public static class PatternCommand extends QuarkusGroupCommand { @Override - public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - return CommandResult.SUCCESS; + public List getCommands() { + return List.of(new IncludePatternCommand(), new ExcludePatternCommand()); } + } @CommandDefinition(name = "include", description = "Sets the current include pattern") 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 237ca1e08668f..b441f10ba2255 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 @@ -21,11 +21,11 @@ import java.util.logging.LogRecord; import java.util.stream.Collectors; +import io.quarkus.deployment.console.QuarkusGroupCommand; import org.aesh.command.Command; import org.aesh.command.CommandDefinition; import org.aesh.command.CommandException; import org.aesh.command.CommandResult; -import org.aesh.command.GroupCommand; import org.aesh.command.GroupCommandDefinition; import org.aesh.command.completer.CompleterInvocation; import org.aesh.command.completer.OptionCompleter; @@ -653,21 +653,13 @@ ConsoleCommandBuildItem logConsoleCommand() { } @GroupCommandDefinition(name = "log", description = "Logging Commands") - public static class LogCommand implements GroupCommand { - - @Option(shortName = 'h', hasValue = false, overrideRequired = true) - public boolean help; + public static class LogCommand extends QuarkusGroupCommand { @Override public List getCommands() { return List.of(new SetLogLevelCommand()); } - @Override - public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - commandInvocation.getShell().writeln(commandInvocation.getHelpInfo()); - return CommandResult.SUCCESS; - } } @CommandDefinition(name = "set-level", description = "Sets the log level for a logger") 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 ce5c83b19fc39..0c7b089c6e793 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 @@ -2,24 +2,17 @@ import java.util.List; +import io.quarkus.deployment.console.QuarkusGroupCommand; import org.aesh.command.Command; -import org.aesh.command.CommandException; -import org.aesh.command.CommandResult; -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; @GroupCommandDefinition(name = "postgres", description = "Postgresql Commands") -public class PostgresCommand implements GroupCommand { +public class PostgresCommand extends QuarkusGroupCommand { private final DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResultBuildItem; - @Option(shortName = 'h', hasValue = false, overrideRequired = true) - public boolean help; - public PostgresCommand(DevServicesLauncherConfigResultBuildItem devServicesLauncherConfigResultBuildItem) { this.devServicesLauncherConfigResultBuildItem = devServicesLauncherConfigResultBuildItem; } @@ -29,9 +22,4 @@ public List getCommands() { return List.of(new PsqlCommand(devServicesLauncherConfigResultBuildItem)); } - @Override - public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - 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 fc28b82441960..8748901d91653 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 @@ -16,17 +16,16 @@ import java.util.Set; import java.util.stream.Collectors; +import io.quarkus.deployment.console.QuarkusGroupCommand; import org.aesh.command.Command; import org.aesh.command.CommandDefinition; import org.aesh.command.CommandException; import org.aesh.command.CommandResult; -import org.aesh.command.GroupCommand; import org.aesh.command.GroupCommandDefinition; import org.aesh.command.completer.CompleterInvocation; 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; @@ -313,13 +312,10 @@ public static boolean isSetByDevServices(Optional getCommands() { return List.of(new SetConfigCommand(configDescriptionsManager)); } - @Override - public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { - commandInvocation.getShell().writeln(commandInvocation.getHelpInfo()); - return CommandResult.SUCCESS; - } } @CommandDefinition(name = "set", description = "Sets a config value", validator = SetValidator.class)