Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import org.jboss.aesh.cl.Arguments;
import org.jboss.aesh.cl.CommandDefinition;
import org.jboss.aesh.console.AeshConsole;
import org.jboss.aesh.console.AeshConsoleBuilder;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.Command;
import org.jboss.aesh.console.command.CommandResult;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.jboss.aesh.console.command.registry.AeshCommandRegistryBuilder;
import org.jboss.aesh.console.command.registry.CommandRegistry;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.aesh.console.settings.SettingsBuilder;
import org.jboss.aesh.io.Resource;
import java.io.IOException;
import java.util.List;
public class AeshConsoleExample {
public static void main(String... args) {
Settings settings = new SettingsBuilder()
.logging(true)
.enableMan(true)
.readInputrc(false)
.create();
CommandRegistry registry = new AeshCommandRegistryBuilder()
.command(ExitCommand.class)
.command(SimpleLsCommand.class)
.create();
AeshConsole aeshConsole = new AeshConsoleBuilder()
.commandRegistry(registry)
.settings(settings)
.prompt(new Prompt("[aesh@rules]$ "))
.create();
aeshConsole.start();
}
@CommandDefinition(name = "ls", description = "list files and directories")
public class SimpleLsCommand implements Command {
@Arguments(description = "list files and directories")
private List<Resource> files;
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
if(files != null) {
for(Resource f : files)
commandInvocation.getShell().out().println(f.toString());
}
return CommandResult.SUCCESS;
}
}
@CommandDefinition(name = "exit", description = "exit")
public class ExitCommand implements Command {
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
commandInvocation.stop();
return CommandResult.SUCCESS;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment