-
-
Save outofcoffee/a8af963e44b42b153265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:[email protected]">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