Skip to content

Instantly share code, notes, and snippets.

@stalep
Created January 26, 2016 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stalep/d4d047a6fc2262205af3 to your computer and use it in GitHub Desktop.
Save stalep/d4d047a6fc2262205af3 to your computer and use it in GitHub Desktop.
import org.jboss.aesh.cl.CommandDefinition;
import org.jboss.aesh.cl.GroupCommandDefinition;
import org.jboss.aesh.cl.Option;
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 java.io.IOException;
/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class ApimanExample {
public static void main(String[] args) {
startConsole();
}
private static void startConsole() {
Settings settings = new SettingsBuilder()
.enableMan(true)
.readInputrc(true)
.create();
CommandRegistry registry = new AeshCommandRegistryBuilder()
.command(ExitCommand.class)
.command(GatewayCommand.class)
.create();
AeshConsole console = new AeshConsoleBuilder()
.commandRegistry(registry)
.settings(settings)
.prompt(new Prompt("[apiman] "))
.create();
console.start();
}
@CommandDefinition(name="exit", description = "exit the program")
public static class ExitCommand implements Command {
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
commandInvocation.stop();
return CommandResult.SUCCESS;
}
}
@CommandDefinition(name = "test", description = "test the gateway")
public static class TestGatewayCommand implements Command {
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@CommandDefinition(name = "show", description = "show the gateway")
public static class ShowGatewayCommand implements Command {
@Option
private String foo;
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@CommandDefinition(name = "create", description = "create the gateway")
public static class CreateGatewayCommand implements Command {
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@CommandDefinition(name = "list", description = "list the gateway")
public static class ListGatewayCommand implements Command {
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@GroupCommandDefinition(name = "gateway", description = "",
groupCommands = {CreateGatewayCommand.class, ListGatewayCommand.class,
ShowGatewayCommand.class, TestGatewayCommand.class})
public static class GatewayCommand implements Command {
@Option(hasValue = false, description = "display this help option")
private boolean help;
@Override
public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
if(help)
commandInvocation.getShell().out().println(commandInvocation.getHelpInfo("gateway"));
else
commandInvocation.getShell().out().println("only executed gate, it doesnt do much...");
return CommandResult.SUCCESS;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment