org.kohsuke.args4j.spi.SubCommands Java Examples

The following examples show how to use org.kohsuke.args4j.spi.SubCommands. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PinotAdministrator.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public void printUsage() {
  LOGGER.info("Usage: pinot-admin.sh <subCommand>");
  LOGGER.info("Valid subCommands are:");

  Class<PinotAdministrator> obj = PinotAdministrator.class;

  for (Field f : obj.getDeclaredFields()) {
    if (f.isAnnotationPresent(SubCommands.class)) {
      SubCommands subCommands = f.getAnnotation(SubCommands.class);

      for (SubCommand subCommand : subCommands.value()) {
        Class<?> subCommandClass = subCommand.impl();
        Command command = null;

        try {
          command = (Command) subCommandClass.newInstance();
          LOGGER.info("\t" + subCommand.name() + "\t<" + command.description() + ">");
        } catch (Exception e) {
          LOGGER.info("Internal Error: Error instantiating class.");
        }
      }
    }
  }
  LOGGER.info("For other crud operations, please refer to ${ControllerAddress}/help.");
}
 
Example #2
Source File: PinotToolLauncher.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public void printUsage() {
  LOGGER.info("Usage: pinot-tools.sh <subCommand>");
  LOGGER.info("Valid subCommands are:");

  Class<PinotToolLauncher> obj = PinotToolLauncher.class;

  for (Field f : obj.getDeclaredFields()) {
    if (f.isAnnotationPresent(SubCommands.class)) {
      SubCommands subCommands = f.getAnnotation(SubCommands.class);

      for (SubCommand subCommand : subCommands.value()) {
        Class<?> subCommandClass = subCommand.impl();
        Command command = null;

        try {
          command = (Command) subCommandClass.newInstance();
          LOGGER.info("\t" + subCommand.name() + "\t<" + command.description() + ">");
        } catch (Exception e) {
          LOGGER.info("Internal Error: Error instantiating class.");
        }
      }
    }
  }
}
 
Example #3
Source File: BuckCommand.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * @return The name that was used to invoke the subcommand, as declared in the annotations above
 */
String getDeclaredSubCommandName() {
  if (subcommand == null) {
    return "no_sub_command";
  } else {
    Class<? extends Command> subcommandClass = subcommand.getClass();
    try {
      SubCommands subCommands =
          this.getClass()
              .getDeclaredField(getSubcommandsFieldName())
              .getAnnotation(SubCommands.class);
      for (SubCommand c : subCommands.value()) {
        if (c.impl().equals(subcommandClass)) {
          return c.name();
        }
      }
      return "unknown_sub_command";
    } catch (NoSuchFieldException e) {
      throw new HumanReadableException(e.getMessage());
    }
  }
}