Java Code Examples for org.apache.commons.cli.Option#setRequired()

The following examples show how to use org.apache.commons.cli.Option#setRequired() . 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: StorageCli.java    From waltz with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option storageOption = Option.builder("s")
            .longOpt("storage")
            .desc("Specify storage in format of host:admin_port")
            .hasArg()
            .build();
    Option cliCfgOption = Option.builder("c")
            .longOpt("cli-config-path")
            .desc("Specify the cli config file path required for ZooKeeper connection string, ZooKeeper root path and SSL config")
            .hasArg()
            .build();
    storageOption.setRequired(false);
    cliCfgOption.setRequired(true);
    options.addOption(storageOption);
    options.addOption(cliCfgOption);
}
 
Example 2
Source File: ZooKeeperCli.java    From waltz with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option partitionOption = Option.builder("p")
            .longOpt("partition")
            .desc("Specify the partition to assign")
            .hasArg()
            .build();
    Option storageOption = Option.builder("s")
            .longOpt("storage")
            .desc("Specify the storage to be assigned to, in format of host:port")
            .hasArg()
            .build();
    Option cliCfgOption = Option.builder("c")
            .longOpt("cli-config-path")
            .desc("Specify the cli config file path required for ZooKeeper connection string, ZooKeeper root path")
            .hasArg()
            .build();

    cliCfgOption.setRequired(true);
    partitionOption.setRequired(true);
    storageOption.setRequired(true);

    options.addOption(cliCfgOption);
    options.addOption(partitionOption);
    options.addOption(storageOption);
}
 
Example 3
Source File: TopicStatusSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("t", "topic", true, "topic name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}
 
Example 4
Source File: TopicListSubCommand.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("c", "clusterModel", false, "clusterModel");
    opt.setRequired(false);
    options.addOption(opt);
    return options;
}
 
Example 5
Source File: KafkaStatsMain.java    From doctorkafka with Apache License 2.0 5 votes vote down vote up
/**
 * Usage: com.pinterest.kafka.KafkaStatsMain --host kafkahost --port 9999
 * --zookeeper datazk001:2181/data05 --topic kafka_metrics
 * --stats_producer_config producer_config.properties --tsdhost localhost:18321
 * --ostrichport 2051 --uptimeinseconds 43200 --pollinginterval 15
 * --kafka_config /etc/kafka/server.properties
 */
private static CommandLine parseCommandLine(String[] args) {

  Option host = new Option(BROKER_NAME, true, "kafka broker");
  host.setRequired(false);
  Option jmxPort = new Option(JMX_PORT, true, "kafka jmx port number");
  jmxPort.setArgName("kafka jmx port number");

  Option zookeeper = new Option(ZOOKEEPER, true, "zk url for metrics topic");
  Option topic = new Option(METRICS_TOPIC, true, "kafka topic for metric messages");
  Option tsdHostPort = new Option(TSD_HOSTPORT, true, "tsd host and port, e.g. localhost:18621");
  Option ostrichPort = new Option(OSTRICH_PORT, true, "ostrich port");
  Option uptimeInSeconds = new Option(UPTIME_IN_SECONDS, true, "uptime in seconds");
  Option pollingInterval = new Option(POLLING_INTERVAL, true, "polling interval in seconds");
  Option kafkaConfig = new Option(KAFKA_CONFIG, true, "kafka server properties file path");
  Option disableEc2metadata = new Option(DISABLE_EC2METADATA, false, "Disable collecting host information via ec2metadata");
  Option statsProducerConfig = new Option(STATS_PRODUCER_CONFIG, true,
      "kafka_stats producer config");
  Option primaryNetworkInterfaceName = new Option(PRIMARY_INTERFACE_NAME, true,
      "network interface used by kafka");

  options.addOption(jmxPort).addOption(host).addOption(zookeeper).addOption(topic)
      .addOption(tsdHostPort).addOption(ostrichPort).addOption(uptimeInSeconds)
      .addOption(pollingInterval).addOption(kafkaConfig).addOption(statsProducerConfig)
      .addOption(primaryNetworkInterfaceName).addOption(disableEc2metadata);

  if (args.length < 6) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example 6
Source File: HttpTLSClient.java    From athenz with Apache License 2.0 5 votes vote down vote up
private static CommandLine parseCommandLine(String[] args) {
    
    Options options = new Options();
    
    Option key = new Option("k", "key", true, "private key path");
    key.setRequired(true);
    options.addOption(key);
    
    Option cert = new Option("c", "cert", true, "certficate path");
    cert.setRequired(true);
    options.addOption(cert);
    
    Option trustStore = new Option("t", "trustStorePath", true, "CA TrustStore path");
    trustStore.setRequired(true);
    options.addOption(trustStore);
    
    Option trustStorePassword = new Option("p", "trustStorePassword", true, "CA TrustStore password");
    trustStorePassword.setRequired(true);
    options.addOption(trustStorePassword);
    
    Option ztsUrl = new Option("u", "url", true, "HTTP Server url");
    ztsUrl.setRequired(true);
    options.addOption(ztsUrl);
    
    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd = null;
    
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("zts-tls-client", options);
        System.exit(1);
    }
    
    return cmd;
}
 
Example 7
Source File: WipeWritePermSubCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("b", "brokerName", true, "broker name");
    opt.setRequired(true);
    options.addOption(opt);
    return options;
}
 
Example 8
Source File: TopicRouteSubCommand.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("t", "topic", true, "topic name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}
 
Example 9
Source File: ThriftLogDumper.java    From singer with Apache License 2.0 5 votes vote down vote up
private static Options buildOptions() {
  Option input = new Option("i", "input", true, "Input thrift logger log file");
  input.setRequired(true);

  Option output = new Option("o", "output", true, "Output file. Default: STDOUT");
  Option maxMessageSize =
      new Option(null, "max-message-size", true,
          "Max thrift message size allowed. Default: 16384");
  Option startOffset = new Option(null, "offset", true,
      "Byte offset from the beginning of the file to start reading. Default: 0");
  Option numOfMessages =
      new Option("n", "number-of-messages", true, "Number of messages to dump. Default: INTMAX");
  Option noTimestamp = new Option(null, "no-timestamp", false, "Output message only");
  Option toJson = new Option(null, "json", false, "Output as JSON format");
  Option pretty = new Option(null, "pretty", false, "Prettifies the JSON formatted messages");
  Option thriftSchema =
      new Option(null, "thrift-schema", true,
          "Thrift schema class used for deserialization. Default: cast message body to String.");

  Options options = new Options();
  options
      .addOption(input)
      .addOption(output)
      .addOption(maxMessageSize)
      .addOption(startOffset)
      .addOption(numOfMessages)
      .addOption(noTimestamp)
      .addOption(toJson)
      .addOption(pretty)
      .addOption(thriftSchema);
  return options;
}
 
Example 10
Source File: DiskCli.java    From waltz with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option deserializerOption = Option.builder("d")
            .longOpt("deserializer")
            .desc("Specify deserializer to use")
            .hasArg()
            .build();
    Option statisticOption = Option.builder("m")
            .longOpt("metadata")
            .desc("Display segment metadata")
            .build();
    Option verifyOption = Option.builder("r")
            .longOpt("record")
            .desc("Display segment record")
            .build();
    Option transactionOption = Option.builder("t")
            .longOpt("transaction")
            .desc("Specify the transaction id to dump. If missing, dump all transactions.")
            .hasArg()
            .build();

    deserializerOption.setRequired(false);
    statisticOption.setRequired(false);
    verifyOption.setRequired(false);
    transactionOption.setRequired(false);

    options.addOption(statisticOption);
    options.addOption(verifyOption);
    options.addOption(transactionOption);
    options.addOption(deserializerOption);
}
 
Example 11
Source File: WipeWritePermSubCommand.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("b", "brokerName", true, "broker name");
    opt.setRequired(true);
    options.addOption(opt);
    return options;
}
 
Example 12
Source File: TopicRouteSubCommand.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("t", "topic", true, "topic name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}
 
Example 13
Source File: WipeWritePermSubCommand.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("b", "brokerName", true, "broker name");
    opt.setRequired(true);
    options.addOption(opt);
    return options;
}
 
Example 14
Source File: ZooKeeperCli.java    From waltz with Apache License 2.0 5 votes vote down vote up
@Override
protected void configureOptions(Options options) {
    Option cliCfgOption = Option.builder("c")
        .longOpt("cli-config-path")
        .desc("Specify the cli config file path required for zooKeeper connection string, zooKeeper root path")
        .hasArg()
        .build();

    cliCfgOption.setRequired(true);

    options.addOption(cliCfgOption);
}
 
Example 15
Source File: ConsumerConnectionSubCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "consumerGroup", true, "consumer group name");
    opt.setRequired(true);
    options.addOption(opt);

    return options;
}
 
Example 16
Source File: ConsumerProgressSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Options buildCommandlineOptions(Options options) {
    Option opt = new Option("g", "groupName", true, "consumer group name");
    opt.setRequired(false);
    options.addOption(opt);

    return options;
}
 
Example 17
Source File: InstanceClientRegister.java    From athenz with Apache License 2.0 4 votes vote down vote up
private static CommandLine parseCommandLine(String[] args) {
    
    Options options = new Options();
    
    Option domain = new Option("d", "domain", true, "domain name");
    domain.setRequired(true);
    options.addOption(domain);
    
    Option service = new Option("s", "service", true, "service name");
    service.setRequired(true);
    options.addOption(service);
    
    Option provider = new Option("p", "provider", true, "provider name");
    provider.setRequired(true);
    options.addOption(provider);
    
    Option instance = new Option("i", "instance", true, "instance id");
    instance.setRequired(true);
    options.addOption(instance);
    
    Option dnsSuffix = new Option("dns", "dnssuffix", true, "provider dns suffix");
    dnsSuffix.setRequired(true);
    options.addOption(dnsSuffix);
    
    Option providerKey = new Option("pk", "providerkey", true, "provider private key path");
    providerKey.setRequired(true);
    options.addOption(providerKey);
    
    Option keyId = new Option("pkid", "providerkeyid", true, "provider private key identifier");
    keyId.setRequired(true);
    options.addOption(keyId);
    
    Option instanceKey = new Option("ik", "instancekey", true, "instance private key path");
    instanceKey.setRequired(true);
    options.addOption(instanceKey);
    
    Option ztsUrl = new Option("z", "ztsurl", true, "ZTS Server url");
    ztsUrl.setRequired(true);
    options.addOption(ztsUrl);
    
    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd = null;
    
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("instance-client", options);
        System.exit(1);
    }
    
    return cmd;
}
 
Example 18
Source File: ZTSAWSCredsClient.java    From athenz with Apache License 2.0 4 votes vote down vote up
private static CommandLine parseCommandLine(String[] args) {
    
    Options options = new Options();
    
    Option domain = new Option("d", "domain", true, "domain name");
    domain.setRequired(true);
    options.addOption(domain);
    
    Option role = new Option("r", "role", true, "role name");
    role.setRequired(true);
    options.addOption(role);
    
    Option key = new Option("k", "key", true, "private key path");
    key.setRequired(true);
    options.addOption(key);
    
    Option cert = new Option("c", "cert", true, "certficate path");
    cert.setRequired(true);
    options.addOption(cert);

    Option trustStore = new Option("t", "trustStorePath", true, "CA TrustStore path");
    trustStore.setRequired(true);
    options.addOption(trustStore);
    
    Option trustStorePassword = new Option("p", "trustStorePassword", true, "CA TrustStore password");
    trustStorePassword.setRequired(true);
    options.addOption(trustStorePassword);
    
    Option ztsUrl = new Option("z", "ztsurl", true, "ZTS Server url");
    ztsUrl.setRequired(true);
    options.addOption(ztsUrl);

    Option externalId = new Option("i", "id", true, "external id");
    externalId.setRequired(false);
    options.addOption(externalId);

    Option minTime = new Option("n", "min", true, "min expiry time in seconds");
    minTime.setRequired(false);
    options.addOption(minTime);

    Option maxTime = new Option("x", "max", true, "max expiry time in seconds");
    maxTime.setRequired(false);
    options.addOption(maxTime);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd = null;
    
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("zts-aws-creds-client", options);
        System.exit(1);
    }
    
    return cmd;
}
 
Example 19
Source File: QueryMetricsReporter.java    From datawave with Apache License 2.0 4 votes vote down vote up
private Options getOptions() {
    Options options = new Options();
    
    instanceOpt = new Option("i", "instance", true, "Accumulo instance name");
    instanceOpt.setArgName("name");
    instanceOpt.setRequired(true);
    options.addOption(instanceOpt);
    
    zookeepersOpt = new Option("zk", "zookeeper", true, "Comma-separated list of ZooKeeper servers");
    zookeepersOpt.setArgName("server[,server]");
    zookeepersOpt.setRequired(true);
    options.addOption(zookeepersOpt);
    
    userOpt = new Option("u", "username", true, "Accumulo username");
    userOpt.setArgName("name");
    userOpt.setRequired(true);
    options.addOption(userOpt);
    
    passwordOpt = new Option("p", "password", true, "Accumulo password");
    passwordOpt.setArgName("passwd");
    passwordOpt.setRequired(true);
    options.addOption(passwordOpt);
    
    beginOpt = new Option("b", "begin", true, "Begin date");
    beginOpt.setArgName("date");
    beginOpt.setRequired(true);
    options.addOption(beginOpt);
    
    endOpt = new Option("e", "end", true, "End date");
    endOpt.setArgName("date");
    endOpt.setRequired(true);
    options.addOption(endOpt);
    
    tableOpt = new Option("t", "table", true, "Specify a table output override for testing purposes.");
    tableOpt.setArgName("table");
    tableOpt.setRequired(false);
    options.addOption(tableOpt);
    
    useAllQueryPagesOpt = new Option("a", "allPages", false, "If present, query latency will use all pages in the query.");
    useAllQueryPagesOpt.setRequired(false);
    useAllQueryPagesOpt.setArgs(0);
    options.addOption(useAllQueryPagesOpt);
    
    verboseSummariesOpt = new Option("v", "verbose", false, "Print extra statistics on queries in the date range.");
    verboseSummariesOpt.setRequired(false);
    verboseSummariesOpt.setArgs(0);
    options.addOption(verboseSummariesOpt);
    
    queryUserOpt = new Option("qu", "queryUser", false, "Limit the metrics to a specific user");
    queryUserOpt.setRequired(false);
    queryUserOpt.setArgs(1);
    queryUserOpt.setArgName("queryUser");
    options.addOption(queryUserOpt);
    
    return options;
}
 
Example 20
Source File: AbstractCli.java    From incubator-iotdb with Apache License 2.0 4 votes vote down vote up
static Options createOptions() {
  Options options = new Options();
  Option help = new Option(HELP_ARGS, false, "Display help information(optional)");
  help.setRequired(false);
  options.addOption(help);

  Option timeFormat = new Option(ISO8601_ARGS, false, "Display timestamp in number(optional)");
  timeFormat.setRequired(false);
  options.addOption(timeFormat);

  Option host = Option.builder(HOST_ARGS).argName(HOST_NAME).hasArg()
      .desc("Host Name (optional, default 127.0.0.1)").build();
  options.addOption(host);

  Option port = Option.builder(PORT_ARGS).argName(PORT_NAME).hasArg()
      .desc("Port (optional, default 6667)")
      .build();
  options.addOption(port);

  Option username = Option.builder(USERNAME_ARGS).argName(USERNAME_NAME).hasArg()
      .desc("User name (required)")
      .required().build();
  options.addOption(username);

  Option password = Option.builder(PASSWORD_ARGS).argName(PASSWORD_NAME).hasArg()
      .desc("password (optional)")
      .build();
  options.addOption(password);

  Option execute = Option.builder(EXECUTE_ARGS).argName(EXECUTE_NAME).hasArg()
      .desc("execute statement (optional)")
      .build();
  options.addOption(execute);

  Option maxPrintCount = Option.builder(MAX_PRINT_ROW_COUNT_ARGS)
      .argName(MAX_PRINT_ROW_COUNT_NAME).hasArg()
      .desc("Maximum number of rows displayed (optional)").build();
  options.addOption(maxPrintCount);

  Option isRpcCompressed = Option.builder(RPC_COMPRESS_ARGS)
      .argName(RPC_COMPRESS_NAME)
      .desc("Rpc Compression enabled or not").build();
  options.addOption(isRpcCompressed);
  return options;
}