当前位置: 首页>>代码示例>>Java>>正文


Java Option.setArgName方法代码示例

本文整理汇总了Java中org.apache.commons.cli.Option.setArgName方法的典型用法代码示例。如果您正苦于以下问题:Java Option.setArgName方法的具体用法?Java Option.setArgName怎么用?Java Option.setArgName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.cli.Option的用法示例。


在下文中一共展示了Option.setArgName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCommandLine

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
private static CommandLine parseCommandLine(String[] args) {

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

    Option metric = new Option(METRICS_NAME, true, "jmx metric name");

    options.addOption(jmxPort).addOption(host).addOption(metric);

    if (args.length < 4) {
      printUsageAndExit();
    }
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, args);
    } catch (ParseException | NumberFormatException e) {
      printUsageAndExit();
    }
    return cmd;
  }
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:23,代码来源:MetricsFetcher.java

示例2: Cli

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
public Cli(String[] args) {

        this.args = args;

        options.addOption(new Option("h", "help", false, "Show Help."));
        Option optGenerate = new Option("g", "generate", true, "Generate a new project based on a configuration file.");
        optGenerate.setArgName("configuration file");
        options.addOption(optGenerate);
        options.addOption(new Option("o", "open", false, "Open the GitHub repository."));
    }
 
开发者ID:massivedisaster,项目名称:kickoff,代码行数:11,代码来源:Cli.java

示例3: createOption

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
public Option createOption() {
	String defaultValue = getDefaultValue();
   	Option option   = OptionBuilder.withLongOpt(name())
   				.withDescription(String.format("%s %s %s",getDescription(),defaultValue==null?"":"Default value: ",defaultValue==null?"":defaultValue))
   				.create(getShortName());
   	if (getArgName()!= null) {
   		option.setArgs(1);
        option.setArgName(getArgName());
   	}
   	return option;
}
 
开发者ID:ideaconsult,项目名称:appdomain,代码行数:12,代码来源:MainApp.java

示例4: registerOptions

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
private static void registerOptions(Options options)
{
	// Declare options
	Option hostOpt = new Option("h", "host", true, "Target server to attack (ip or domain)");
	hostOpt.setArgName("string");
	hostOpt.setRequired(true);
	Option portOpt = new Option("p", "port", true, "Port of the target server (default: 25565)");
	portOpt.setArgName("int");
	Option modOpt = new Option("m", "module", true, "Module to execute");
	modOpt.setArgName("module");
	modOpt.setRequired(true);
	Option confOpt = new Option("c", "configure", false, "Configure a module");
	Option listOpt = new Option("l", "list", false, "List available modules");
	Option genUsrOpt = new Option("gu", "gen-user", true, "Generate username (random, natural, const:%username%)");
	genUsrOpt.setArgName("method");
	Option usrOpt = new Option("u", "username", true, "A minecraft username");
	usrOpt.setArgName("name");
	Option accOpt = new Option("cr", "credentials", true, "Credentials of a minecraft account. (Format: username/email:password)");
	accOpt.setArgName("creds");
	Option aProxyOpt = new Option("ap", "auth-proxy", true, "A proxy used for authentication. Format: host:port (https)");
	aProxyOpt.setArgName("proxy");
	Option sProxyOpt = new Option("sp", "socks-proxy", true, "A proxy used to connect to a server. Format: host:port (socks)");
	sProxyOpt.setArgName("proxy");

	// Add options
	options.addOption(hostOpt);
	options.addOption(portOpt);
	options.addOption(modOpt);
	options.addOption(confOpt);
	options.addOption(listOpt);
	options.addOption(genUsrOpt);
	options.addOption(usrOpt);
	options.addOption(accOpt);
	options.addOption(aProxyOpt);
	options.addOption(sProxyOpt);
}
 
开发者ID:xTACTIXzZ,项目名称:Hydrazine,代码行数:37,代码来源:Hydrazine.java

示例5: parseCommandLine

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
/**
 *  Usage:  com.pinterest.kafka.KafkaStatsMain  --host kafkahost --port 9999
 *             --zookeeper datazk001:2181/data05  --topic  kafka_metrics
 *             --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");

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

  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;
}
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:39,代码来源:KafkaStatsMain.java

示例6: OptionBuilder

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
private OptionBuilder(String shortName, String longName) {
    option = new Option(shortName, "");
    option.setLongOpt(longName);
    option.setArgName(longName);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:6,代码来源:CliToolConfig.java

示例7: doMain

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
void doMain(String[] args) {
	Options o = new Options();

	Option help = new Option("h", "help", false,
			"display this help message");
	o.addOption(help);

	Option primes = new Option("p", "primes", true,
			"print <count> first prime numbers");
	primes.setArgName("count");
	o.addOption(primes);

	Option generatedBean = new Option("g", "generatedbean", true,
			"use generated javabean by setting s=<sValue>");
	generatedBean.setArgName("sValue");
	o.addOption(generatedBean);

	Option unsignedByte = new Option("u", "unsigned-byte", true,
			"use joulu-unsigned-byte to convert <int> to"
					+ " unsigned byte and display information");
	unsignedByte.setArgName("int");
	o.addOption(unsignedByte);

	CommandLineParser parser = new DefaultParser();

	CommandLine cmd;
	try {
		cmd = parser.parse(o, args);
	} catch (ParseException e) {
		showHelpAndExit(o);
		return;
	}
	if (cmd.hasOption(help.getOpt())) {
		showHelpAndExit(o);
		return;
	}
	if (cmd.hasOption(primes.getOpt())) {
		int count = Integer.parseInt(cmd.getOptionValue(primes.getOpt()));
		printPrimes(count);
		return;
	}
	if (cmd.hasOption(generatedBean.getOpt())) {
		String v = cmd.getOptionValue(generatedBean.getOpt());
		useGeneratedBean(v);
		return;
	}
	if (cmd.hasOption(unsignedByte.getOpt())) {
		int value = Integer
				.parseInt(cmd.getOptionValue(unsignedByte.getOpt()));
		useJouluUnsignedByte(value);
		return;
	}
	showHelpAndExit(o);
	return;
}
 
开发者ID:wipu,项目名称:iwant-demo,代码行数:56,代码来源:IwantDemoCli.java

示例8: run

import org.apache.commons.cli.Option; //导入方法依赖的package包/类
@Override
public int run(String[] args) throws Exception {

  Options opts = new Options();
  opts.addOption(HELP_CMD, false, "Displays help for all commands.");
  opts.addOption(STATUS_CMD, true, "Prints the status report of the node.");
  opts.addOption(LIST_CMD, false, "List all running nodes. " +
      "Supports optional use of -states to filter nodes " +
      "based on node state, all -all to list all nodes.");
  Option nodeStateOpt = new Option(NODE_STATE_CMD, true,
      "Works with -list to filter nodes based on input comma-separated list of node states.");
  nodeStateOpt.setValueSeparator(',');
  nodeStateOpt.setArgs(Option.UNLIMITED_VALUES);
  nodeStateOpt.setArgName("States");
  opts.addOption(nodeStateOpt);
  Option allOpt = new Option(NODE_ALL, false,
      "Works with -list to list all nodes.");
  opts.addOption(allOpt);
  opts.getOption(STATUS_CMD).setArgName("NodeId");

  int exitCode = -1;
  CommandLine cliParser = null;
  try {
    cliParser = new GnuParser().parse(opts, args);
  } catch (MissingArgumentException ex) {
    sysout.println("Missing argument for options");
    printUsage(opts);
    return exitCode;
  }

  if (cliParser.hasOption("status")) {
    if (args.length != 2) {
      printUsage(opts);
      return exitCode;
    }
    printNodeStatus(cliParser.getOptionValue("status"));
  } else if (cliParser.hasOption("list")) {
    Set<NodeState> nodeStates = new HashSet<NodeState>();
    if (cliParser.hasOption(NODE_ALL)) {
      for (NodeState state : NodeState.values()) {
        nodeStates.add(state);
      }
    } else if (cliParser.hasOption(NODE_STATE_CMD)) {
      String[] types = cliParser.getOptionValues(NODE_STATE_CMD);
      if (types != null) {
        for (String type : types) {
          if (!type.trim().isEmpty()) {
            nodeStates.add(NodeState.valueOf(
                org.apache.hadoop.util.StringUtils.toUpperCase(type.trim())));
          }
        }
      }
    } else {
      nodeStates.add(NodeState.RUNNING);
    }
    listClusterNodes(nodeStates);
  } else if (cliParser.hasOption(HELP_CMD)) {
    printUsage(opts);
    return 0;
  } else {
    syserr.println("Invalid Command Usage : ");
    printUsage(opts);
  }
  return 0;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:66,代码来源:NodeCLI.java


注:本文中的org.apache.commons.cli.Option.setArgName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。