Interface PluginBasedCommand
-
- All Known Implementing Classes:
ProjectCommand
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) @SuppressFieldNotInitialized private ImmutableList
modes; @Override protected ImmutableList extends PluginBasedSubCommand> getSubCommands() { return modes; } @Override protected String getTypeOptionName() { return "--mode"; } } interface ExamplePluginBasedSubCommandFactory extends PluginBasedSubCommandFactory { } @Extention class SomeExamplePluginBasedSubCommand implements ExamplePluginBasedSubCommandFactory { @Override 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 Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description String
getShortDescription()
com.google.common.collect.ImmutableList<? extends PluginBasedSubCommand>
getSubCommands()
String
getTypeOptionName()
default void
printUsage(PrintStream stream)
Prints the usage to the provided stream.
-
-
-
Method Detail
-
getSubCommands
com.google.common.collect.ImmutableList<? extends PluginBasedSubCommand> getSubCommands()
- Returns:
- all subcommands known to this command.
-
getTypeOptionName
String getTypeOptionName()
- Returns:
- the name of the option that is used to control which subcommand is invoked.
-
getShortDescription
String getShortDescription()
- Returns:
- a pharse that describes the purpose of this command.
-
printUsage
default void printUsage(PrintStream stream)
Prints the usage to the provided stream.
-
-