Skip to content

Instantly share code, notes, and snippets.

@stalep
Created July 4, 2015 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stalep/98103347df1dd9b67fd1 to your computer and use it in GitHub Desktop.
Save stalep/98103347df1dd9b67fd1 to your computer and use it in GitHub Desktop.
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