Skip to content
sk89q edited this page Aug 19, 2014 · 3 revisions

Intake is a set of libraries for processing user input commands. Its goal is to provide a framework for implementing commands and tools to reduce boilerplate code.

Concepts

Command processing in Intake involves several concepts:

  • A Description is metadata about a command. They provide information on accepted parameters, a short description, a longer help text, a usage string (i.e. <name> [<age>]), a list of potential permissions that are checked. Descriptions, however, do not determine how a command is executed and the list of permissions is never verified.
  • The CommandCallable is the invokable portion of a command that will perform its purpose when it is called. Callables return a Description, so consider callables a combination of command metadata + the runnable code. In addition, callables have a testPermission() method to test whether the command can be executed by the caller.
  • Dispatchers keep track of registered commands and call the right one. In addition, dispatchers also implement CommandCallable themselves, which means you can make sub-commands by registering it under one dispatcher that is then registered under your main dispatcher.
  • CommandMapping is a combination of a command's list of aliases (the names of the command), CommandCallable, and its Description. Generally you don't need to make mappings because dispatchers will generate them for you.

The reason while it's split up into several interfaces is to allow re-use. You can swap around descriptions, callables, and command aliases easily. That said, you may end up using the "parametric builder," so you would not even need to bother with most of these concepts too much.

Parametric builder

One large part of Intake is the ParametricBuilder class, which builds CommandCallables from methods in a class that have been annotated with @Command. This portion of Intake is entirely optional, though it is perhaps the main reason to use Intake.

An example of a command recognized by ParametricBuilder is seen below.

public class MyCommands {

    @Command(aliases = "age", desc = "Set age")
    @Require("example.age")
    public void setAge(User user, @Optional @Default("20") int age) {
        user.setAge(age);
        user.message("Your age was set to: " + age);
    }

}

For more information, see the parametric builder documentation.