Search in sources :

Example 1 with Cli

use of io.airlift.airline.Cli in project druid by druid-io.

the class Main method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    final Cli.CliBuilder<Runnable> builder = Cli.builder("druid");
    builder.withDescription("Druid command-line runner.").withDefaultCommand(Help.class).withCommands(Help.class, Version.class);
    builder.withGroup("server").withDescription("Run one of the Druid server types.").withDefaultCommand(Help.class).withCommands(CliCoordinator.class, CliHistorical.class, CliBroker.class, CliRealtime.class, CliOverlord.class, CliMiddleManager.class, CliRouter.class);
    builder.withGroup("example").withDescription("Run an example").withDefaultCommand(Help.class).withCommands(CliRealtimeExample.class);
    builder.withGroup("tools").withDescription("Various tools for working with Druid").withDefaultCommand(Help.class).withCommands(DruidJsonValidator.class, PullDependencies.class, CreateTables.class, InsertSegment.class, DumpSegment.class, ResetCluster.class, ValidateSegments.class);
    builder.withGroup("index").withDescription("Run indexing for druid").withDefaultCommand(Help.class).withCommands(CliHadoopIndexer.class);
    builder.withGroup("internal").withDescription("Processes that Druid runs \"internally\", you should rarely use these directly").withDefaultCommand(Help.class).withCommands(CliPeon.class, CliInternalHadoopIndexer.class);
    final Injector injector = GuiceInjectors.makeStartupInjector();
    final ExtensionsConfig config = injector.getInstance(ExtensionsConfig.class);
    final Collection<CliCommandCreator> extensionCommands = Initialization.getFromExtensions(config, CliCommandCreator.class);
    for (CliCommandCreator creator : extensionCommands) {
        creator.addCommands(builder);
    }
    final Cli<Runnable> cli = builder.build();
    try {
        final Runnable command = cli.parse(args);
        if (!(command instanceof Help)) {
            // Hack to work around Help not liking being injected
            injector.injectMembers(command);
        }
        command.run();
    } catch (ParseException e) {
        System.out.println("ERROR!!!!");
        System.out.println(e.getMessage());
        System.out.println("===");
        cli.parse(new String[] { "help" }).run();
        System.exit(1);
    }
}
Also used : Cli(io.airlift.airline.Cli) Help(io.airlift.airline.Help) Injector(com.google.inject.Injector) ParseException(io.airlift.airline.ParseException) ExtensionsConfig(io.druid.guice.ExtensionsConfig)

Aggregations

Injector (com.google.inject.Injector)1 Cli (io.airlift.airline.Cli)1 Help (io.airlift.airline.Help)1 ParseException (io.airlift.airline.ParseException)1 ExtensionsConfig (io.druid.guice.ExtensionsConfig)1