High Level API

The high level API enables you to create commands with a variety of options/arguments, completors, validators, ++ fast and efficiently. The way to enable the high level API is to use the AeshConsole. The only way to initiate AeshConsole is to use the AeshConsoleBuilder class. AeshConsoleBuilder accept several different objects, all of them are described below except Settings which can be found here.

CommandRegistry

CommandRegistry is the registry where all the commands are stored. Æsh provide a default CommandRegistry if no external is provided.

CommandInvocationServices

It is possible to specify your own CommandInvocation implementation and to enable that you have to specify your own CommandInvocationProvider. It is possible to have multiple CommandInvocationProviders and this is controlled by the CommandInvocationService. Æsh provide a default implementation for all these classes.

CommandNotFoundHandler

Æsh allow you to specify a CommandNotFoundHandler that will be called when a user tries to execute a command which name is not found. Æsh will fall back to a default handler if none is provided.

ManProvider

To make the man command useful it is important to provide a custom ManProvider. There is no need to implement this if man isnt enabled.

Prompt

Specify the Prompt that will be shown at startup. It is possible to change the prompt when needed during runtime.

In the end a small example to tie it all together
public 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(LsCommand.class)
              .command(TestConsoleCommand.class)
              .create();
      AeshConsole aeshConsole = new AeshConsoleBuilder()
              .commandRegistry(registry)
              .manProvider(new ManProviderExample())
              .settings(settings)
              .prompt(new Prompt("[aesh@rules]$ "))
              .create();

      aeshConsole.start();
  }
}
back to top