當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。