当前位置: 首页>>代码示例>>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;未经允许,请勿转载。