io.airlift.airline.Help Java Examples

The following examples show how to use io.airlift.airline.Help. 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: TestingPrestoServerLauncher.java    From presto with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
        throws Exception
{
    TestingPrestoServerLauncher launcher = singleCommand(TestingPrestoServerLauncher.class).parse(args);
    if (launcher.helpOption.showHelpIfRequested()) {
        return;
    }
    try {
        launcher.validateOptions();
    }
    catch (IllegalStateException e) {
        System.out.println("ERROR: " + e.getMessage());
        System.out.println();
        Help.help(launcher.commandMetadata);
        return;
    }
    launcher.run();
}
 
Example #2
Source File: Launcher.java    From presto with Apache License 2.0 6 votes vote down vote up
protected void run(String[] args)
{
    CommandFactory<Runnable> commandFactory = new ExtensionsProvidingCommandFactory<>(getExtensions());
    Cli.CliBuilder<Runnable> cli = Cli.<Runnable>builder("launcher")
            .withCommandFactory(commandFactory) // TODO ignored
            .withDefaultCommand(Help.class)
            .withCommand(Help.class);

    cli
            .withGroup("env")
            .withDefaultCommand(Help.class) // TODO should be group aware https://github.com/airlift/airline/issues/72? Otherwise it's required until https://github.com/airlift/airline/pull/71
            .withCommand(EnvironmentUp.class)
            .withCommand(EnvironmentDown.class)
            .withCommand(EnvironmentList.class);

    cli
            .withGroup("test")
            .withDefaultCommand(Help.class) // TODO should be group aware https://github.com/airlift/airline/issues/72? Otherwise it's required until https://github.com/airlift/airline/pull/71
            .withCommand(TestRun.class);

    cli.build().parse(commandFactory, args).run();
}
 
Example #3
Source File: StageLibCli.java    From datacollector with Apache License 2.0 6 votes vote down vote up
boolean doMain(String[] args) {
  Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("streamsets stagelib-cli vault-credentialstore")
      .withDescription("StreamSets Data Collector Vault Credential Store CLI")
      .withDefaultCommand(Help.class)
      .withCommands(Help.class, VaultShowIdCommand.class);

  try {
    builder.build().parse(args).run();
    return true;
  } catch (Exception ex) {
    if(Arrays.asList(args).contains("--stack")) {
      ex.printStackTrace(System.err);
    } else {
      System.err.println(ex.getMessage());
    }
    return false;
  }
}
 
Example #4
Source File: MetadataGeneratorMain.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main(String[] args) {
  System.setProperty("sdc.conf.dir", System.getProperty("user.dir"));
  Configuration.setFileRefsBaseDir(new File(System.getProperty("user.dir")));

  Cli.CliBuilder<Runnable> cliBuilder = Cli.
      <Runnable>builder("streamsets metadata-generator")
      .withDescription("Generates pipeline executor and stage libraries metadata for StreamSets Cloud")
      .withDefaultCommand(Help.class)
      .withCommands(
          Help.class,
          ExecutorMetadataCommand.class,
          StageLibMetadataCommand.class
      );

  Runnable runnable = cliBuilder.build().parse(args);
  runnable.run();
}
 
Example #5
Source File: JavaKeystoreCredentialStoreCli.java    From datacollector with Apache License 2.0 6 votes vote down vote up
boolean doMain(String[] args) {
  Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("streamsets stagelib-cli jks-credentialstore")
      .withDescription("StreamSets Data Collector Java Keystore Credential Store CLI")
      .withDefaultCommand(Help.class)
      .withCommands(
          Help.class,
          ListCredentialsCommand.class,
          AddCredentialCommand.class,
          DeleteCredentialCommand.class
      );

  try {
    builder.build().parse(args).run();
    return true;
  } catch (Exception ex) {
    if(Arrays.asList(args).contains("--stack")) {
      ex.printStackTrace(System.err);
    } else {
      System.err.println(ex.getMessage());
    }
    return false;
  }
}
 
Example #6
Source File: Runner.java    From grpc-proxy with Apache License 2.0 6 votes vote down vote up
private static Cli<Runnable> cli() {
  final CliBuilder<Runnable> builder = Cli.builder("grpc-proxy");

  builder
      .withDescription("A set of example services for testing a gRPC proxy service.")
      .withDefaultCommand(Help.class)
      .withCommand(Help.class)
      .withCommand(HelloWorldClient.Cmd.class);

  builder
      .withGroup("server")
      .withDescription("Run a server")
      .withDefaultCommand(Help.class)
      .withCommand(Help.class)
      .withCommand(ProxyRpcServer.Cmd.class)
      .withCommand(LegacyHttpServer.Cmd.class)
      .withCommand(HelloWorldServer.Cmd.class);

  return builder.build();
}
 
Example #7
Source File: StreamsetsCredentialStoreCli.java    From datacollector with Apache License 2.0 6 votes vote down vote up
boolean doMain(String[] args) {
  Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("streamsets stagelib-cli streamsets-credentialstore")
      .withDescription("StreamSets Data Collector Streamsets Credential Store CLI")
      .withDefaultCommand(Help.class)
      .withCommands(
          Help.class,
          DefaultSshKeyInfoCommand.class
      );

  try {
    builder.build().parse(args).run();
    return true;
  } catch (Exception ex) {
    if(Arrays.asList(args).contains("--stack")) {
      ex.printStackTrace(System.err);
    } else {
      System.err.println(ex.getMessage());
    }
    return false;
  }
}
 
Example #8
Source File: SchCli.java    From datacollector with Apache License 2.0 6 votes vote down vote up
boolean doMain(String[] args) {
  Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("streamsets sch")
      .withDescription("StreamSets Data Collector CLI interface for Control Hub")
      .withDefaultCommand(Help.class)
      .withCommands(
        Help.class,
        RegisterCommand.class,
        UnregisterCommand.class
      );

  try {
    builder.build().parse(args).run();
    return true;
  } catch (Exception ex) {
    System.err.println(ex.getMessage());
    return false;
  }
}
 
Example #9
Source File: Cli.java    From java-json-benchmark with MIT License 5 votes vote down vote up
public static void main(String[] args) throws RunnerException {
    CliBuilder<Runnable> builder = io.airlift.airline.Cli.<Runnable>builder("bench")
        .withDescription("Benchmark JSON libraries")
        .withDefaultCommand(Help.class)
        .withCommands(Help.class, InfoCommand.class, SerializationCommand.class, DeserializationCommand.class);

    io.airlift.airline.Cli<Runnable> gitParser = builder.build();
    gitParser.parse(args).run();
}
 
Example #10
Source File: Configurable.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void helpGroup(String groupName, String commandName) {
   for (CommandGroupMetadata group : global.getCommandGroups()) {
      if (group.getName().equals(groupName)) {
         for (CommandMetadata command : group.getCommands()) {
            if (command.getName().equals(commandName)) {
               Help.help(command);
            }
         }
         break;
      }
   }
}
 
Example #11
Source File: AlfrescoCLI.java    From alfresco-client-sdk with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Cli.CliBuilder<Runnable> builder = Cli.<Runnable> builder("alfclient")
            .withDescription("Sample Alfresco Command Line Client").withDefaultCommand(Help.class)
            .withCommands(Help.class, AlfrescoCommands.infoUser.class)
            .withCommands(Help.class, AlfrescoCommands.listRoot.class);

    Cli<Runnable> gitParser = builder.build();

    gitParser.parse(args).run();
}
 
Example #12
Source File: ToolkitMain.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main(String[] args) {

  initialProjectVersion();

  String scriptName = System.getProperty("script.name");
  Cli.CliBuilder<Runnable> builder = null;
  if (StringUtils.isNotEmpty(scriptName)) {
    builder = Cli.builder(scriptName);
  } else {
    builder = Cli.builder("java -jar cli-" + projectVersion + ".jar");
  }

  builder.withDescription("Microservice development toolkit(version " + projectVersion
      + "). ");
  builder.withDefaultCommand(Help.class);
  builder.withCommands(
      CodeGenerate.class, DocGenerate.class,
      CheckStyle.class, CheckStyleAbbr.class,
      CheckCompatibility.class, CheckCompatibilityAbbr.class,
      Help.class
  );
  try {
    Runnable cmd = builder.build().parse(args);

    cmd.run();
  } catch (ValidationFailedException ex) {
    ex.printStackTrace(System.err);
    System.exit(1);
  }
}
 
Example #13
Source File: SwaggerCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    String version = Version.readVersionFromResources();
    @SuppressWarnings("unchecked")
    Cli.CliBuilder<Runnable> builder =
            Cli.<Runnable>builder("swagger-codegen-cli")
                    .withDescription(
                            String.format(
                                    "Swagger code generator CLI (version %s). More info on swagger.io",
                                    version))
                    .withDefaultCommand(Langs.class)
                    .withCommands(Generate.class, Meta.class, Langs.class, Help.class,
                            ConfigHelp.class, Validate.class, Version.class);

    builder.build().parse(args).run();
}
 
Example #14
Source File: PrestoVerifier.java    From presto with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
    Cli<Runnable> verifierParser = Cli.<Runnable>builder("verifier")
            .withDescription("Presto Verifier")
            .withDefaultCommand(Help.class)
            .withCommand(Help.class)
            .withCommand(VerifyCommand.class)
            .build();

    verifierParser.parse(args).run();
}
 
Example #15
Source File: StrongboxCLI.java    From strongbox with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    CliBuilder<Runnable> builder = Cli.<Runnable>builder("strongbox")
            .withDescription("Strongbox")
            .withDefaultCommand(Help.class)
            .withCommands(Help.class);

    builder.withCommand(Global.CustomHelp.class);
    builder.withCommand(Global.Version.class);
    builder.withCommand(Global.VersionOption.class);

    builder.withGroup("group")
            .withDescription("Manage Secret Groups")
            .withDefaultCommand(Group.GroupHelp.class)
            .withCommands(Group.Create.class, Group.List.class, Group.Info.class, Group.Delete.class, Group.AttachAdmin.class, Group.DetachAdmin.class, Group.AttachReadOnly.class, Group.DetachReadOnly.class, Group.BackupCommand.class, Group.RestoreCommand.class, Group.MigrateCommand.class);

    builder.withGroup("secret")
            .withDescription("Manage Secrets for a Secret Group")
            .withDefaultCommand(Secret.SecretHelp.class)
            .withCommands(Secret.Create.class, Secret.AddVersion.class, Secret.Get.class, Secret.GetLatest.class, Secret.Delete.class, Secret.ListNames.class, Secret.ListVersions.class, Secret.Update.class);

    builder.withCommand(Gui.OpenGui.class);

    Cli<Runnable> parser = builder.build();
    globalMetadata = parser.getMetadata();

    try {
        parser.parse(args).run();
    } catch (ParseArgumentsUnexpectedException exception) {
        Optional<String> globalOptions = exception.getUnparsedInput().stream()
                .filter(Global.Option::contains)
                .findAny();

        System.err.println(exception.getMessage());
        if (globalOptions.isPresent()) {
            System.err.println(String.format(
                    "Please note: global options like '%s' must be placed before the command,\n" +
                    "  e.g. 'strongbox --global-option [global-option-value] <command> [<args>]'\n" +
                    "  see 'strongbox help <command>' for more information about ordering.",
                    globalOptions.get()));
        } else {
            System.err.println("See 'strongbox help'.");
        }

        System.exit(1);
    } catch (Exception e) {
        boolean stacktrace = stacktraceIsSet(parser.getMetadata(), args);

        if (!stacktrace) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        throw e;
    }
}
 
Example #16
Source File: Group.java    From strongbox with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    Help.help(StrongboxCLI.globalMetadata, Collections.singletonList("group"));
}
 
Example #17
Source File: Secret.java    From strongbox with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    Help.help(StrongboxCLI.globalMetadata, Collections.singletonList("secret"));
}
 
Example #18
Source File: DataCollector.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("cli")
      .withDescription("StreamSets Data Collector CLI")
      .withDefaultCommand(Help.class)
      .withCommands(
          Help.class,
          PingCommand.class
      );

  builder.withGroup("definitions")
      .withDescription("Returns Pipeline & Stage Configuration definitions")
      .withDefaultCommand(DefinitionsCommand.class)
      .withCommands(DefinitionsCommand.class);

  builder.withGroup("store")
      .withDescription("Store Commands")
      .withDefaultCommand(ListPipelinesCommand.class)
      .withCommands(
          ListPipelinesCommand.class,
          ExportPipelineCommand.class,
          ImportPipelineCommand.class,
          CreatePipelineCommand.class,
          GetPipelineConfigCommand.class,
          GetPipelineRulesCommand.class,
          DeletePipelineCommand.class,
          UpdatePipelineConfigCommand.class,
          UpdatePipelineRulesCommand.class,
          DeletePipelinesByFilteringCommand.class
      );

  builder.withGroup("manager")
      .withDescription("Manager Commands")
      .withDefaultCommand(PipelineStatusCommand.class)
      .withCommands(
          PipelineStatusCommand.class,
          PipelineMetricsCommand.class,
          StartPipelineCommand.class,
          StopPipelineCommand.class,
          AlertsCommand.class,
          DeleteAlertCommand.class,
          SampledRecordsCommand.class,
          ResetOriginCommand.class,
          ErrorRecordsCommand.class,
          ErrorMessagesCommand.class,
          SnapshotListCommand.class,
          SnapshotCaptureCommand.class,
          SnapshotStatusCommand.class,
          SnapshotDataCommand.class,
          SnapshotDeleteCommand.class,
          PipelineHistoryCommand.class,
          DeletePipelineHistoryCommand.class,
          GetCommittedOffsetsCommand.class,
          UpdateCommittedOffsetsCommand.class
      );

  builder.withGroup("system")
      .withDescription("System Commands")
      .withDefaultCommand(InfoCommand.class)
      .withCommands(
          ConfigurationCommand.class,
          DirectoriesCommand.class,
          InfoCommand.class,
          CurrentUserCommand.class,
          ServerTimeCommand.class,
          ShutdownCommand.class,
          ThreadsCommand.class,
          EnableDPMCommand.class,
          DisableDPMCommand.class
      );

  builder.withGroup("preview")
      .withDescription("Preview Commands")
      .withDefaultCommand(RunPreviewCommand.class)
      .withCommands(
          RunPreviewCommand.class,
          PreviewStatusCommand.class,
          PreviewDataCommand.class,
          StopPreviewCommand.class,
          ValidatePipelineCommand.class
      );

  try {
    builder.build().parse(args).run();
  } catch (ParseOptionMissingException | ParseArgumentsUnexpectedException ex) {
    if(Arrays.asList(args).contains("--stack")) {
      ex.printStackTrace();
    } else {
      System.out.println(ex.getMessage());
    }
  }

}
 
Example #19
Source File: PluginRemoveCommand.java    From gyro with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeSubCommand() throws Exception {
    if (getPlugins().isEmpty()) {
        Help.help(MetadataLoader.loadCommand(PluginRemoveCommand.class));
        return;
    }

    List<DirectiveNode> removeNodes = getPluginNodes()
        .stream()
        .filter(this::pluginNodeExist)
        .collect(Collectors.toList());

    List<DirectiveNode> invalidNodes = getPluginNodes()
        .stream()
        .filter(f -> !pluginNodeExist(f))
        .collect(Collectors.toList());

    StringBuilder sb = new StringBuilder();
    int lineNumber = 0;
    for (String line : load()) {
        boolean skipLine = false;
        for (DirectiveNode pluginNode : removeNodes) {
            if (lineNumber >= pluginNode.getStartLine() && lineNumber <= pluginNode.getStopLine()) {
                skipLine = true;
            }
        }

        if (!skipLine) {
            sb.append(line);
            sb.append("\n");
        }

        lineNumber++;
    }

    save(sb.toString());

    GyroCore.ui().write("\n");

    invalidNodes.stream()
        .map(this::toPluginString)
        .map(p -> String.format("@|bold %s|@ was not installed.%n", p))
        .forEach(GyroCore.ui()::write);

    removeNodes.stream()
        .map(this::toPluginString)
        .map(p -> String.format("@|bold %s|@ has been removed.%n", p))
        .forEach(GyroCore.ui()::write);
}
 
Example #20
Source File: PluginAddCommand.java    From gyro with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeSubCommand() throws Exception {
    if (getPlugins().isEmpty()) {
        Help.help(MetadataLoader.loadCommand(PluginAddCommand.class));
        return;
    }

    GyroCore.ui().write("\n");

    Set<String> installedPlugins = getPlugins()
        .stream()
        .filter(f -> !pluginNotExist(f))
        .collect(Collectors.toSet());

    installedPlugins.stream()
        .map(p -> String.format("@|bold %s|@ is already installed.%n", p))
        .forEach(GyroCore.ui()::write);

    Set<String> plugins = getPlugins()
        .stream()
        .filter(this::pluginNotExist)
        .collect(Collectors.toSet());

    if (plugins.isEmpty()) {
        return;
    }

    if (repositories == null) {
        repositories = new ArrayList<>();

        repositories.add(RepositorySettings.CENTRAL);
    }

    getRepositoryNodes()
        .stream()
        .map(this::toRepositoryUrl)
        .forEach(s -> repositories.add(new RemoteRepository.Builder(s, "default", s).build()));

    plugins = plugins
        .stream()
        .filter(this::validate)
        .collect(Collectors.toSet());

    StringBuilder sb = new StringBuilder();
    load()
        .stream()
        .map(l -> l + "\n")
        .forEach(sb::append);

    plugins.forEach(p -> sb.append(String.format("%s '%s'%n", "@plugin:", p)));
    save(sb.toString());

    plugins.stream()
        .map(p -> String.format("@|bold %s|@ has been added.%n", p))
        .forEach(GyroCore.ui()::write);
}
 
Example #21
Source File: AbstractMain.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected String getUsageInfo(Cli<BrooklynCommand> parser) {
    StringBuilder help = new StringBuilder();
    help.append("\n");
    Help.help(parser.getMetadata(), Collections.<String>emptyList(), help);
    return help.toString();
}
 
Example #22
Source File: Denominator.java    From denominator with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  CliBuilder<Runnable> builder = Cli.<Runnable>builder("denominator")
      .withDescription("Denominator: Portable control of DNS clouds")
      .withDefaultCommand(Help.class)
      .withCommand(Help.class)
      .withCommand(PrintVersion.class)
      .withCommand(ListProviders.class);

  builder.withGroup("zone")
      .withDescription("manage zones")
      .withDefaultCommand(ZoneList.class)
      .withCommand(ZoneList.class)
      .withCommand(ZoneAdd.class)
      .withCommand(ZoneUpdate.class)
      .withCommand(ZoneDelete.class);

  builder.withGroup("record")
      .withDescription("manage resource record sets in a zone")
      .withDefaultCommand(ResourceRecordSetList.class)
      .withCommand(ResourceRecordSetList.class)
      .withCommand(ResourceRecordSetGet.class)
      .withCommand(ResourceRecordSetAdd.class)
      .withCommand(ResourceRecordSetApplyTTL.class)
      .withCommand(ResourceRecordSetReplace.class)
      .withCommand(ResourceRecordSetRemove.class)
      .withCommand(ResourceRecordSetDelete.class);

  builder.withGroup("geo")
      .withDescription("manage geo resource record sets in a zone")
      .withDefaultCommand(GeoResourceRecordSetList.class)
      .withCommand(GeoTypeList.class)
      .withCommand(GeoRegionList.class)
      .withCommand(GeoResourceRecordSetList.class)
      .withCommand(GeoResourceRecordSetGet.class)
      .withCommand(GeoResourceRecordSetApplyTTL.class)
      .withCommand(GeoResourceRecordAddRegions.class);

  Cli<Runnable> denominatorParser = builder.build();
  try {
    denominatorParser.parse(args).run();
  } catch (RuntimeException e) {
    if (e instanceof NullPointerException) {
      e.printStackTrace();
    }
    System.err.println(";; error: " + e.getMessage());
    System.exit(1);
  }
  System.exit(0);
}