Interface CommandBinding


public interface CommandBinding

The code the build generates for one @Command class, through which the parser creates the command, sets its fields and runs it without reflection.

Applications do not implement this; the build writes one implementation per command and fails if a command cannot be bound.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    call(Object command)
    Runs the command and answers its exit code.
    convert(int slot, String text)
    Converts the text of one value of the argument in slot to the type of its field.
    A new instance of the command.
    void
    inject(Object command, Object parent, CommandSpec spec)
    Hands the command the instance of its enclosing command, for a CommandLine.ParentCommand field, and its own model, for a CommandLine.Spec field.
    boolean
    Whether the command has a body: it is a Runnable or a Callable.
    void
    set(Object command, int slot, Object value)
    Stores a converted value in the field of slot.
    The model of the command, with its subcommands.
  • Method Details

    • spec

      CommandSpec spec()
      The model of the command, with its subcommands.
    • create

      Object create() throws Exception
      A new instance of the command.
      Throws:
      Exception
    • convert

      Object convert(int slot, String text) throws Exception
      Converts the text of one value of the argument in slot to the type of its field. A failure is reported as an invalid value.
      Throws:
      Exception
    • set

      void set(Object command, int slot, Object value) throws Exception
      Stores a converted value in the field of slot. For an array or a list field, value is a java.util.List of converted elements.
      Throws:
      Exception
    • inject

      void inject(Object command, Object parent, CommandSpec spec) throws Exception
      Hands the command the instance of its enclosing command, for a CommandLine.ParentCommand field, and its own model, for a CommandLine.Spec field.
      Throws:
      Exception
    • runnable

      boolean runnable()
      Whether the command has a body: it is a Runnable or a Callable.
    • call

      int call(Object command) throws Exception
      Runs the command and answers its exit code.
      Throws:
      Exception