Java Code Examples for com.beust.jcommander.JCommander#usage()

The following examples show how to use com.beust.jcommander.JCommander#usage() . 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: SetPassword.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public static SetPasswordOptions parse(String[] cliArgs) {
  SetPasswordOptions args = new SetPasswordOptions();
  JCommander jc = JCommander.newBuilder().addObject(args).build();
  jc.setProgramName("dremio-admin set-password");

  try {
    jc.parse(cliArgs);
  } catch (ParameterException p) {
    AdminLogger.log(p.getMessage());
    jc.usage();
    System.exit(1);
  }

  if(args.help) {
    jc.usage();
    System.exit(0);
  }

  if(args.userName != null && args.password == null) {
    char[] pwd = System.console().readPassword("password: ");
    args.password = new String(pwd);
  }
  return args;
}
 
Example 2
Source File: KafkaProcessingRunner.java    From bpmn.ai with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void initialize(String[] arguments) {
    KafkaProcessingArguments kafkaProcessingArguments = KafkaProcessingArguments.getInstance();

    // instantiate JCommander
    // Use JCommander for flexible usage of Parameters
    final JCommander jCommander = JCommander.newBuilder().addObject(KafkaProcessingArguments.getInstance()).build();
    try {
        jCommander.parse(arguments);
    } catch (final ParameterException e) {
        LOG.error("Parsing of parameters failed. Error message: " + e.getMessage());
        jCommander.usage();
        System.exit(1);
    }

    //parse arguments to create SparkRunnerConfig
    kafkaProcessingArguments.createOrUpdateSparkRunnerConfig(this.sparkRunnerConfig);

    // Delete destination files, required to avoid exception during runtime
    FileUtils.deleteQuietly(new File(this.sparkRunnerConfig.getTargetFolder()));

    BpmnaiLogger.getInstance().writeInfo("Starting data processing with data from: " + this.sparkRunnerConfig.getSourceFolder());
}
 
Example 3
Source File: CLI.java    From swagger-diff with Apache License 2.0 6 votes vote down vote up
public void run(JCommander jCommander) {
    if (help){
        jCommander.setProgramName("java -jar swagger-diff.jar");
        jCommander.usage();
        return;
    }
    if (v){
        JCommander.getConsole().println("1.2.2");
        return;
    }

    SwaggerDiff diff = SwaggerDiff.SWAGGER_VERSION_V2.equals(version)
            ? SwaggerDiff.compareV2(oldSpec, newSpec) : SwaggerDiff.compareV1(oldSpec, newSpec);

    String render = getRender(outputMode).render(diff);
    JCommander.getConsole().println(render);
}
 
Example 4
Source File: ConnectorDocGenerator.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    MainArgs mainArgs = new MainArgs();

    JCommander commander = new JCommander();
    try {
        commander.setProgramName("connector-doc-gen");
        commander.addObject(mainArgs);
        commander.parse(args);
        if (mainArgs.help) {
            commander.usage();
            Runtime.getRuntime().exit(0);
            return;
        }
    } catch (Exception e) {
        commander.usage();
        Runtime.getRuntime().exit(-1);
        return;
    }

    ConnectorDocGenerator docGen = new ConnectorDocGenerator();
    docGen.generatorConnectorYamls(mainArgs.outputDir);
}
 
Example 5
Source File: ProducerExample.java    From pulsar with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        final Arguments arguments = new Arguments();
        JCommander jc = new JCommander(arguments);
        jc.setProgramName("pulsar-kafka-test");

        try {
            jc.parse(args);
        } catch (ParameterException e) {
            System.out.println(e.getMessage());
            jc.usage();
            System.exit(-1);
        }

        if (arguments.help) {
            jc.usage();
            System.exit(-1);
        }

        publishMessage(arguments);
    }
 
Example 6
Source File: SamRecordComparision.java    From cramtools with Apache License 2.0 5 votes vote down vote up
private static void printUsage(JCommander jc) {
	StringBuilder sb = new StringBuilder();
	sb.append("\n");
	jc.usage(sb);

	System.out.println("Version " + Bam2Cram.class.getPackage().getImplementationVersion());
	System.out.println(sb.toString());
}
 
Example 7
Source File: LoadSimulationController.java    From pulsar with Apache License 2.0 5 votes vote down vote up
/**
 * Start a controller with command line arguments.
 *
 * @param args
 *            Arguments to pass in.
 */
public static void main(String[] args) throws Exception {
    final MainArguments arguments = new MainArguments();
    final JCommander jc = new JCommander(arguments);
    jc.setProgramName("pulsar-perf simulation-controller");
    try {
        jc.parse(args);
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        jc.usage();
        System.exit(-1);
    }
    (new LoadSimulationController(arguments)).run();
}
 
Example 8
Source File: Application.java    From acme_client with MIT License 5 votes vote down vote up
private static void printHelpInfo(JCommander jCommander){
    StringBuilder usage = new StringBuilder();
    jCommander.usage(usage);
    System.out.println(usage.toString());
    String format = "%10s%n";
    System.out.format(format, Parameters.MAIN_USAGE.toString());
}
 
Example 9
Source File: DownloadReferences.java    From cramtools with Apache License 2.0 5 votes vote down vote up
private static void printUsage(JCommander jc) {
	StringBuilder sb = new StringBuilder();
	sb.append("\n");
	jc.usage(sb);

	System.out.println("Version " + DownloadReferences.class.getPackage().getImplementationVersion());
	System.out.println(sb.toString());
}
 
Example 10
Source File: CLITest.java    From swagger-diff with Apache License 2.0 5 votes vote down vote up
@Test
public void testCLI() {
    CLI cli = new CLI();
    String[] argv = { "-v", "2.0", "-old", "http://petstore.swagger.io/v2/swagger.json",
            "--help" };
    JCommander commander = JCommander.newBuilder().addObject(cli).build();

    commander.setProgramName("java swagger-diff.jar");
    commander.usage();
    commander.parse(argv);
    Assert.assertEquals(cli.getVersion(), "2.0");
    Assert.assertEquals(cli.getOldSpec(), "http://petstore.swagger.io/v2/swagger.json");
}
 
Example 11
Source File: Runner.java    From ratis with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  if (args.length == 0) {
    System.err.println("No command type specified: ");
    return;
  }
  List<SubCommandBase> commands = initializeCommands(args[0]);
  Runner runner = new Runner();

  if (commands == null) {
    System.err.println("Wrong command type: " + args[0]);
    return;
  }
  String[] newArgs = new String[args.length - 1];
  System.arraycopy(args, 1, newArgs, 0, args.length - 1);

  JCommander.Builder builder = JCommander.newBuilder().addObject(runner);
  commands.forEach(command -> builder
      .addCommand(command.getClass().getSimpleName().toLowerCase(), command));
  JCommander jc = builder.build();
  try {
    jc.parse(newArgs);
    Optional<SubCommandBase> selectedCommand = commands.stream().filter(
        command -> command.getClass().getSimpleName().toLowerCase()
            .equals(jc.getParsedCommand())).findFirst();
    if (selectedCommand.isPresent()) {
      selectedCommand.get().run();
    } else {
      jc.usage();
    }
  } catch (ParameterException exception) {
    System.err.println("Wrong parameters: " + exception.getMessage());
    jc.usage();
  }

}
 
Example 12
Source File: TS2SequiturGrammar.java    From grammarviz2_src with GNU General Public License v2.0 5 votes vote down vote up
private static void parseArgs(String[] args) {
    TS2GrammarParameters params = new TS2GrammarParameters();
    JCommander jct = new JCommander(params, args);

    if (0 == args.length) {
        jct.usage();
    } else {
        logParams();
    }
}
 
Example 13
Source File: BenchmarkWorker.java    From openmessaging-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    final Arguments arguments = new Arguments();
    JCommander jc = new JCommander(arguments);
    jc.setProgramName("benchmark-worker");

    try {
        jc.parse(args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        jc.usage();
        System.exit(-1);
    }

    if (arguments.help) {
        jc.usage();
        System.exit(-1);
    }

    Configuration conf = new CompositeConfiguration();
    conf.setProperty(Stats.STATS_PROVIDER_CLASS, PrometheusMetricsProvider.class.getName());
    conf.setProperty("prometheusStatsHttpPort", arguments.statsPort);
    Stats.loadStatsProvider(conf);
    StatsProvider provider = Stats.get();
    provider.start(conf);

    Runtime.getRuntime().addShutdownHook(new Thread(
        () -> provider.stop(),
        "benchmark-worker-shutdown-thread"));

    // Dump configuration variables
    log.info("Starting benchmark with config: {}", writer.writeValueAsString(arguments));

    // Start web server
    Javalin app = Javalin.start(arguments.httpPort);

    new WorkerHandler(app, provider.getStatsLogger("benchmark"));
}
 
Example 14
Source File: Mirus.java    From mirus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] argv) {
  Mirus.Args args = new Mirus.Args();
  JCommander jCommander =
      JCommander.newBuilder()
          .programName(OffsetStatus.class.getSimpleName())
          .addObject(args)
          .build();
  try {
    jCommander.parse(argv);
  } catch (Exception e) {
    jCommander.usage();
    throw e;
  }
  if (args.help) {
    jCommander.usage();
    System.exit(1);
  }

  try {
    Map<String, String> workerProps =
        !args.workerPropertiesFile.isEmpty()
            ? Utils.propsToStringMap(Utils.loadProps(args.workerPropertiesFile))
            : Collections.emptyMap();

    applyOverrides(args.overrides, workerProps);

    Mirus mirus = new Mirus();
    Connect connect = mirus.startConnect(workerProps);

    // Shutdown will be triggered by Ctrl-C or via HTTP shutdown request
    connect.awaitStop();
  } catch (Throwable t) {
    log.error("Stopping due to error", t);
    Exit.exit(2);
  }
}
 
Example 15
Source File: RegistryTestServerMain.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
  RegistryTestServerMain serverMain = new RegistryTestServerMain();
  JCommander jCommander = new JCommander(serverMain);
  jCommander.setProgramName("dr-run server");
  jCommander.parse(args);
  if (serverMain.help) {
    jCommander.usage();
    return;
  }
  serverMain.run();
}
 
Example 16
Source File: HoodieMultiTableDeltaStreamer.java    From hudi with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
  final Config config = new Config();
  JCommander cmd = new JCommander(config, null, args);
  if (config.help || args.length == 0) {
    cmd.usage();
    System.exit(1);
  }
  JavaSparkContext jssc = UtilHelpers.buildSparkContext("multi-table-delta-streamer", Constants.LOCAL_SPARK_MASTER);
  try {
    new HoodieMultiTableDeltaStreamer(config, jssc).sync();
  } finally {
    jssc.stop();
  }
}
 
Example 17
Source File: BamToCram.java    From cramtools with Apache License 2.0 5 votes vote down vote up
private static void printUsage(JCommander jc) {
	StringBuilder sb = new StringBuilder();
	sb.append("\n");
	jc.usage(sb);

	System.out.println("Version " + Bam2Cram.class.getPackage().getImplementationVersion());
	System.out.println(sb.toString());
}
 
Example 18
Source File: BaseInputs.java    From support-diagnostics with Apache License 2.0 5 votes vote down vote up
public List<String> parseInputs(String[] args){
    logger.info(Constants.CONSOLE, "Processing diagnosticInputs...");
    jCommander = new JCommander(this);
    jCommander.setCaseSensitiveOptions(true);
    jCommander.parse(args);
    // If we're in help just shut down.
    if (help) {
        jCommander.usage();
        throw new ShowHelpException();
    }

    return ObjectUtils.defaultIfNull(validateDir(outputDir), emptyList);

}
 
Example 19
Source File: RunQueryCommand.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public String getUsage() {
    final JCommander parser = new JCommander(new RunParameters());

    final StringBuilder usage = new StringBuilder();
    parser.usage(usage);
    return usage.toString();
}
 
Example 20
Source File: MultiLangDaemon.java    From amazon-kinesis-client with Apache License 2.0 4 votes vote down vote up
void printUsage(final JCommander jCommander, final String message) {
    if (StringUtils.isNotEmpty(message)) {
        System.err.println(message);
    }
    jCommander.usage();
}