use of org.aesh.command.invocation.CommandInvocation in project quarkus by quarkusio.
the class AeshConsole method runAeshCli.
public void runAeshCli() {
if (ConsoleCliManager.commands.isEmpty()) {
System.out.println("No commands registered, please wait for Quarkus to start before using the console");
return;
}
try {
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.builder().enableExport(false).enableAlias(true).aliasManager(new AliasManager(Paths.get(System.getProperty("user.home")).resolve(ALIAS_FILE).toFile(), true)).connection(delegateConnection).commandRegistry(registry).build();
aeshConsole = new ReadlineConsole(settings);
aeshConsole.setPrompt("quarkus$ ");
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
aeshConsole.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, "Quarkus integrated CLI thread");
t.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.aesh.command.invocation.CommandInvocation in project infinispan by infinispan.
the class Help method execute.
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
Shell shell = commandInvocation.getShell();
if (manPages == null || manPages.size() == 0) {
shell.writeln("Call `help <command>` where command is one of:");
List<TerminalString> commandNames = ((ContextAwareCommandInvocation) commandInvocation).getContext().getRegistry().getAllCommandNames().stream().map(n -> new TerminalString(n)).collect(Collectors.toList());
// then we print out the completions
shell.write(Parser.formatDisplayListTerminalString(commandNames, shell.size().getHeight(), shell.size().getWidth()));
// then on the next line we write the line again
shell.writeln("");
return CommandResult.SUCCESS;
}
if (manPages.size() <= 0) {
shell.write("No manual entry for " + manPages.get(0) + Config.getLineSeparator());
return CommandResult.SUCCESS;
}
if (manProvider == null) {
shell.write("No manual provider defined");
return CommandResult.SUCCESS;
}
InputStream inputStream = manProvider.getManualDocument(manPages.get(0));
if (inputStream != null) {
setCommandInvocation(commandInvocation);
try {
fileParser.setInput(inputStream);
afterAttach();
} catch (IOException ex) {
throw new CommandException(ex);
}
}
return CommandResult.SUCCESS;
}
use of org.aesh.command.invocation.CommandInvocation in project infinispan by infinispan.
the class GraalReflectionCommand method execute.
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if (help) {
commandInvocation.getHelpInfo("graalreflection");
} else {
Class<Command<CommandInvocation>> clazz = loadCommand(command);
if (clazz != null) {
CommandContainerBuilder<CommandInvocation> builder = new AeshCommandContainerBuilder<>();
try {
CommandContainer<CommandInvocation> container = builder.create(clazz);
GraalReflectionFileGenerator graalFileGenerator = new GraalReflectionFileGenerator();
try (BufferedWriter w = Files.newBufferedWriter(Paths.get(container.getParser().getProcessedCommand().name().toLowerCase() + "_reflection.json"), StandardOpenOption.CREATE)) {
graalFileGenerator.generateReflection(container.getParser(), w);
}
container.getParser().getProcessedCommand();
} catch (CommandLineParserException | IOException e) {
e.printStackTrace();
}
} else
commandInvocation.println("Could not load command: " + command);
}
return CommandResult.SUCCESS;
}
Aggregations