/** * Make sure that if there are args with multiple names (e.g. "-log" and "-verbose"), the usage * will only display it once. */ public void repeatedArgs() { Cli<Args1> parser = singleCommandParser(Args1.class); CommandMetadata command = find( parser.getMetadata().getDefaultGroupCommands(), compose(equalTo("Args1"), CommandMetadata.nameGetter())); Assert.assertEquals(command.getAllOptions().size(), 8); }
private void verifyCommandOrdering(String[] commandNames, Class<?>... commands) { CliBuilder<Object> builder = Cli.buildCli("foo"); for (Class<?> command : commands) { builder = builder.withCommand(command); } Cli<?> parser = builder.build(); final List<CommandMetadata> commandParsers = parser.getMetadata().getDefaultGroupCommands(); Assert.assertEquals(commandParsers.size(), commands.length); int i = 0; for (CommandMetadata commandParser : commandParsers) { Assert.assertEquals(commandParser.getName(), commandNames[i++]); } }
public static void main(String[] args) { CliBuilder<Runnable> builder = Cli.<Runnable>builder("denominator") .withDescription("dns manager") .withDefaultCommand(Help.class) .withCommand(Help.class) .withCommand(ListProviders.class); builder .withGroup("zone") .withDescription("manage zones") .withDefaultCommand(ZoneList.class) .withCommand(ZoneList.class); builder .withGroup("record") .withDescription("manage resource record sets in a zone") .withDefaultCommand(ResourceRecordSetList.class) .withCommand(ResourceRecordSetList.class); Cli<Runnable> denominatorParser = builder.build(); denominatorParser.parse(args).run(); }
@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, CliBridge.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(ConvertProperties.class, DruidJsonValidator.class, PullDependencies.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(); } }