Skip to content

Commit

Permalink
Merge pull request #23125 from stuartwdouglas/23036
Browse files Browse the repository at this point in the history
Improve terminal help text
  • Loading branch information
gsmet authored Jan 24, 2022
2 parents 5d51dfe + e194757 commit 088bb94
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<CommandInvocation> commandBuilder = AeshCommandRegistryBuilder.builder();
ConsoleCliManager.commands.forEach(commandBuilder::command);

CommandRegistry registry = commandBuilder
.create();
Settings settings = SettingsBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,24 +525,28 @@ 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<Command> 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")
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -27,6 +31,7 @@ public List<Command> getCommands() {

@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return null;
commandInvocation.getShell().writeln(commandInvocation.getHelpInfo());
return CommandResult.SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -293,11 +294,14 @@ private boolean isSetByDevServices(Optional<DevServicesLauncherConfigResultBuild
return false;
}

@GroupCommandDefinition(name = "config", description = "Config Commands")
@GroupCommandDefinition(name = "config", description = "Config Editing Commands")
public static class ConfigCommandGroup implements GroupCommand {

final ConfigDescriptionsManager configDescriptionsManager;

@Option(shortName = 'h', hasValue = false, overrideRequired = true)
public boolean help;

public ConfigCommandGroup(ConfigDescriptionsManager configDescriptionsManager) {
this.configDescriptionsManager = configDescriptionsManager;
}
Expand All @@ -309,6 +313,7 @@ public List<Command> getCommands() {

@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().writeln(commandInvocation.getHelpInfo());
return CommandResult.SUCCESS;
}
}
Expand Down

0 comments on commit 088bb94

Please sign in to comment.