io.airlift.airline.ParseArgumentsUnexpectedException Java Examples

The following examples show how to use io.airlift.airline.ParseArgumentsUnexpectedException. 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: 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 #2
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());
    }
  }

}