當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultParser類代碼示例

本文整理匯總了Java中org.apache.commons.cli.DefaultParser的典型用法代碼示例。如果您正苦於以下問題:Java DefaultParser類的具體用法?Java DefaultParser怎麽用?Java DefaultParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultParser類屬於org.apache.commons.cli包,在下文中一共展示了DefaultParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseCommandLine

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
/**
 *  Usage:  URPChecker  \
 *             -brokerstatszk    datazk001:2181/data07    \
 *             -brokerstatstopic brokerstats              \
 *             -clusterzk  m10nzk001:2181,...,m10nzk007:2181/m10n07
 */
private static CommandLine parseCommandLine(String[] args) {
  Option zookeeper = new Option(ZOOKEEPER, true, "cluster zookeeper");
  options.addOption(zookeeper);

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

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:24,代碼來源:URPChecker.java

示例2: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    Options options = getOptions();
    try {
        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(options, args);

        String[] streamId = StringUtils.split(cmd.getOptionValue("stream", DEFAULT_STREAM_ID), '/');
        if(streamId.length != 2) {
            throw new IllegalArgumentException("Stream spec must be in the form [scope]/[stream]");
        }

        final URI controllerURI = URI.create(cmd.getOptionValue("uri", DEFAULT_CONTROLLER_URI));
        new NoopReader().run(streamId[0], streamId[1], controllerURI);
    }
    catch (ParseException e) {
        System.out.format("%s.%n", e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("NoopReader", options);
        System.exit(1);
    }
}
 
開發者ID:pravega,項目名稱:pravega-samples,代碼行數:22,代碼來源:NoopReader.java

示例3: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
  CommandLineParser parser = new DefaultParser();
  CommandLine line = parser.parse(CLI_OPTIONS, args);
  if (!line.hasOption("conf")) {
    System.err.println("No configuration file is specified");
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("athenax-server", CLI_OPTIONS);
    System.exit(1);
  }

  try {
    String confFile = line.getOptionValue("conf");
    AthenaXConfiguration conf = AthenaXConfiguration.load(Paths.get(confFile).toFile());
    new AthenaXServer().start(conf);
  } catch (IOException | ClassNotFoundException e) {
    System.err.println("Failed to parse configuration.");
    throw e;
  }
}
 
開發者ID:uber,項目名稱:AthenaX,代碼行數:20,代碼來源:AthenaXServer.java

示例4: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public final static void main(String[] args) throws Exception {

        logger.debug(format("%s called with arguments: '%s'.", GetChangeStatus.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
        Options options = new Options();
        Commands.Helpers.addStandardParameters(options);

        if(helpRequested(args)) {
            handleHelpOption(format("%s <changeId>", getCommandName(GetChangeStatus.class)),
                    "Returns 'true' if the change specified by <changeId> is in development. Otherwise 'false'.", new Options()); return;
        }

        CommandLine commandLine = new DefaultParser().parse(options, args);
        new GetChangeStatus(
                getHost(commandLine),
                getUser(commandLine),
                getPassword(commandLine),
                getChangeId(commandLine)).execute();
    }
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:19,代碼來源:GetChangeStatus.java

示例5: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
protected static void main(Class<? extends TransportRelated> clazz, String[] args, String usage, String helpText) throws Exception {

        logger.debug(format("%s called with arguments: %s", clazz.getSimpleName(), Commands.Helpers.getArgsLogString(args)));

        Options options = new Options();
        Commands.Helpers.addStandardParameters(options);

        if(helpRequested(args)) {
            handleHelpOption(usage, helpText, new Options()); return;
        }

        CommandLine commandLine = new DefaultParser().parse(options, args);

        newInstance(clazz, getHost(commandLine),
                getUser(commandLine),
                getPassword(commandLine),
                getChangeId(commandLine),
                getTransportId(commandLine)).execute();
    }
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:20,代碼來源:TransportRelated.java

示例6: getCommandName

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
private static String getCommandName(String[] args) throws ParseException {

        Options opts = new Options();
        asList(CMOptions.HELP, CMOptions.VERSION, CMOptions.HOST, CMOptions.USER, CMOptions.PASSWORD).stream().map(
           new Function<Option, Option>() {

              @Override
              public Option apply(Option o) {
                Option c = CMOptions.clone(o);
                c.setRequired(false);
                return c;
              }
          }).forEach(o -> opts.addOption(o));

          CommandLine parser = new DefaultParser().parse(opts, args, true);
          if(parser.getArgs().length == 0) {
              throw new CMCommandLineException(format("Canmnot extract command name from arguments: '%s'.",
                        getArgsLogString(args)));
          }
          String commandName = parser.getArgs()[0];
          logger.debug(format("Command name '%s' extracted from command line '%s'.", commandName, getArgsLogString(args)));
          return commandName;
    }
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:24,代碼來源:Commands.java

示例7: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public final static void main(String[] args) throws Exception {

        logger.debug(format("%s called with arguments: '%s'.", GetChangeTransports.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
        Options options = new Options();
        Commands.Helpers.addStandardParameters(options);


        options.addOption(modifiableOnlyOption);

        if(helpRequested(args)) {
            handleHelpOption(format("%s [SUBCOMMAND_OPTIONS] <changeId>", getCommandName(GetChangeTransports.class)),
                    "Returns the ids of the transports for the change represented by <changeId>.",
                      new Options().addOption(modifiableOnlyOption)); return;
        }

        CommandLine commandLine = new DefaultParser().parse(options, args);

        new GetChangeTransports(
                getHost(commandLine),
                getUser(commandLine),
                getPassword(commandLine),
                getChangeId(commandLine),
                commandLine.hasOption(modifiableOnlyOption.getOpt())).execute();
    }
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:25,代碼來源:GetChangeTransports.java

示例8: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public final static void main(String[] args) throws Exception {
    logger.debug(format("%s called with arguments: '%s'.", ReleaseTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
    Options options = new Options();
    Commands.Helpers.addStandardParameters(options);

    if(helpRequested(args)) {
        handleHelpOption(
            format("%s <changeId> <transportId>", getCommandName(ReleaseTransport.class)),
            "Releases the transport specified by <changeId>, <transportId>.", new Options()); return;
    }

    CommandLine commandLine = new DefaultParser().parse(options, args);

    new ReleaseTransport(getHost(commandLine),
            getUser(commandLine),
            getPassword(commandLine),
            getChangeId(commandLine),
            TransportRelated.getTransportId(commandLine)).execute();
}
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:20,代碼來源:ReleaseTransport.java

示例9: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public final static void main(String[] args) throws Exception {
    logger.debug(format("%s called with arguments: '%s'.", UploadFileToTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
    Options options = new Options();
    Commands.Helpers.addStandardParameters(options);

    if(helpRequested(args)) {
        handleHelpOption(format("%s <changeId> <transportId> <applicationId> <filePath>", getCommandName(UploadFileToTransport.class)),
                "Uploads the file specified by <filePath> to transport <transportId> for change <changeId>. "
                + "<applicationId> specifies how the file needs to be handled on server side.", new Options()); return;
    }

    CommandLine commandLine = new DefaultParser().parse(options, args);

    new UploadFileToTransport(
            getHost(commandLine),
            getUser(commandLine),
            getPassword(commandLine),
            getChangeId(commandLine),
            getArg(commandLine, 2, "transportId"),
            getArg(commandLine, 3, "applicationId"),
            getArg(commandLine, 4, "filePath")).execute();
}
 
開發者ID:SAP,項目名稱:devops-cm-client,代碼行數:23,代碼來源:UploadFileToTransport.java

示例10: generateCommandLine

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
/**
 * "Parsing" stage of command-line processing demonstrated with
 * Apache Commons CLI.
 *
 * @param options Options from "definition" stage.
 * @param commandLineArguments Command-line arguments provided to application.
 * @return Instance of CommandLine as parsed from the provided Options and
 *    command line arguments; may be {@code null} if there is an exception
 *    encountered while attempting to parse the command line options.
 */
private static CommandLine generateCommandLine(
   final Options options, final String[] commandLineArguments)
{
   final CommandLineParser cmdLineParser = new DefaultParser();
   CommandLine commandLine = null;
   try
   {
      commandLine = cmdLineParser.parse(options, commandLineArguments);
   }
   catch (ParseException parseException)
   {
      out.println(
           "ERROR: Unable to parse command-line arguments "
         + Arrays.toString(commandLineArguments) + " due to: "
         + parseException);
   }
   return commandLine;
}
 
開發者ID:dustinmarx,項目名稱:java-cli-demos,代碼行數:29,代碼來源:MainWithBuilder.java

示例11: processArguments

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
private void processArguments(String[] args) throws org.apache.commons.cli.ParseException {

		Options opts = new Options(); // Setting CLI options
		opts.addOption("gui", "Whether to use the GUI or not. ('yes' or 'no')");
		opts.addOption("help", "Shows this page");
		opts.addOption("license", "Show license info.");

		CommandLine cl = new DefaultParser().parse(opts, args); // Parsing
																// CLI
																// options

		if (cl.hasOption("help"))
			showHelp();

		if (cl.hasOption("license"))
			showLicense();

		setGui(cl.hasOption("gui"));
	}
 
開發者ID:Electro-Light,項目名稱:ElectroLight-Penetration-Testing,代碼行數:20,代碼來源:Main.java

示例12: main

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("h", true, "Messaging host");
    options.addOption("p", true, "Messaging port");
    options.addOption("q", true, "Queue");
    options.addOption("u", false, "Print this help");

    CommandLineParser parser = new DefaultParser();

    try {

      CommandLine cmd = parser.parse(options, args);

      if (cmd.hasOption("u")) {

        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Sender", options);

      } else {

        String messagingHost = cmd.getOptionValue("h", MESSAGING_HOST);
        int messagingPort = Integer.parseInt(cmd.getOptionValue("p", String.valueOf(MESSAGING_PORT)));
        String address = cmd.getOptionValue("q", QUEUE);

        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
        props.put("connectionfactory.myFactoryLookup", String.format("amqp://%s:%d", messagingHost, messagingPort));
        props.put("queue.myDestinationLookup", address);

        LOG.info("Starting server : connecting to [{}:{}]", messagingHost, messagingPort);

        Server sender = new Server();
        sender.run(props);
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
 
開發者ID:ppatierno,項目名稱:amqp-kafka-demo,代碼行數:41,代碼來源:Server.java

示例13: parseForHelp

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
static void parseForHelp(String[] args) {
    
    // parse for help options
    try {
        Options helpOnly = new Options();
        helpOnly.addOption(options.getOption("h"));
        CommandLine cli = new DefaultParser().parse(helpOnly, args, true);
        
        // no -h option - do nothing
        if (!cli.hasOption("h")) {
            return;
        }
    } catch (ParseException pe) {
        System.err.println(pe.getMessage());
        System.exit(-1);
    }

    // print help text
    new HelpFormatter().printHelp("java -jar sgc-xxx.jar", "Simple Glacier Client (sgc) | Version: 0.1\n\n", options, "\n"+"See: https://github.com/arjuan/simple-glacier-client"+"\n\n", true);
}
 
開發者ID:arjuan,項目名稱:simple-glacier-client,代碼行數:21,代碼來源:SimpleGlacierClient.java

示例14: parseCommandLine

import org.apache.commons.cli.DefaultParser; //導入依賴的package包/類
private static CommandLine parseCommandLine(String[] args) {
  if (args.length < 4) {
    printUsageAndExit();
  }

  Option zookeeper = new Option(ZOOKEEPER, true, "zookeeper connection string");
  Option statsTopic = new Option(STATS_TOPIC, true, "kafka topic for broker stats");
  options.addOption(zookeeper).addOption(statsTopic);

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:19,代碼來源:BrokerStatsReader.java

示例15: parseCommandLine

import org.apache.commons.cli.DefaultParser; //導入依賴的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


注:本文中的org.apache.commons.cli.DefaultParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。