Interface PluginBasedCommand

  • All Known Implementing Classes:

    public interface PluginBasedCommand
    An abstract class that provides basic capabilities for commands that use subcommands loaded from plugins.

    Implementations of this class will have logic to control common logic of a particular plugin-based command. For example, buck project command will have an implementation that implements this class and adds some common domain-independent logic to route a particular invocation to some implementation loaded from plugins.

    Typical example of usage:

       class ExamplePluginBasedCommand extends PluginBasedCommand {
        @PluginBasedSubCommands(factoryClass = ExamplePluginBasedSubCommandFactory.class)
         private ImmutableList modes;
         protected ImmutableList getSubCommands() {
           return modes;
         protected String getTypeOptionName() {
           return "--mode";
       interface ExamplePluginBasedSubCommandFactory extends PluginBasedSubCommandFactory {
       class SomeExamplePluginBasedSubCommand implements ExamplePluginBasedSubCommandFactory {
         SomeExamplePluginBasedSubCommand createSubCommand() {
           return new SomeExamplePluginBasedSubCommand();

    Key points:

    • Sub commands needs to be instantiated using factories
    • Plugin subcommand factories have to implement PluginBasedSubCommandFactory.
    • Plugin subcommands have to implement PluginBasedSubCommand.
    • getTypeOptionName() is used to control which option is used to select a subcommand. The logic in this class uses that method for help screen only. The particular implementations need to use the option with that name to select a particular subcommand.
    • Method Detail

      • getSubCommands<? extends PluginBasedSubCommand> getSubCommands()
        all subcommands known to this command.
      • getTypeOptionName

        String getTypeOptionName()
        the name of the option that is used to control which subcommand is invoked.
      • getShortDescription

        String getShortDescription()
        a pharse that describes the purpose of this command.
      • printUsage

        default void printUsage​(PrintStream stream)
        Prints the usage to the provided stream.