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


Java CommandLineParser.parse方法代码示例

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


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

示例1: testProfile

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
@Test
public void testProfile() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[]{});
    final Set<Protocol> list = new HashSet<>(Arrays.asList(
            new SwiftProtocol(),
            new ProfilePlistReader(new ProtocolFactory(Collections.singleton(new SwiftProtocol() {
                @Override
                public boolean isEnabled() {
                    return true;
                }
            })))
                    .read(new Local("../profiles/default/Rackspace US.cyberduckprofile"))
    ));
    assertTrue(new Host(new ProtocolFactory(list).forName("rackspace"), "identity.api.rackspacecloud.com", 443, "/cdn.cyberduck.ch/", new Credentials("u", null))
            .compareTo(new CommandLineUriParser(input, new ProtocolFactory(list)).parse("rackspace://[email protected]/")) == 0);

}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:19,代码来源:CommandLineUriParserTest.java

示例2: parseCommandLine

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的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

示例3: parseArguments

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
private static CommandLine parseArguments(Configuration conf, Options options, String[] args)
    throws ParseException, IOException {
  GenericOptionsParser genParser = new GenericOptionsParser(conf, args);
  String[] remainingArgs = genParser.getRemainingArgs();
  CommandLineParser parser = new PosixParser();
  return parser.parse(options, remainingArgs);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:8,代码来源:ThriftServer.java

示例4: parseCommandLine

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
private static void parseCommandLine(String[] args) {
	Options options = new Options();

	Option input = new Option("n", "timed-iterations", true, "number of iterations of timing loop");
	input.setRequired(false);
	options.addOption(input);

	Option output = new Option("w", "warmup-iterations", true, "number of warm-up iterations before timing loop");
	output.setRequired(false);
	options.addOption(output);

	Option hourly = new Option("h", "hourly", false, "whether to use hourly data");
	hourly.setRequired(false);
	options.addOption(hourly);

	CommandLineParser parser = new DefaultParser();
	HelpFormatter formatter = new HelpFormatter();
	CommandLine cmd;

	try {
		cmd = parser.parse(options, args);
	} catch (ParseException e) {
		System.out.println(e.getMessage());
		formatter.printHelp("StlPerfTest", options);

		System.exit(1);
		return;
	}

	if (cmd.hasOption("hourly")) {
		System.out.println("Running hourly stress test");
		fRunCo2 = false;
		fTimedIterations = 200;
		fWarmupIterations = 30;
	} else {
		System.out.println("Running CO2 test");
		fTimedIterations = 2000;
		fWarmupIterations = 30;
	}

	String nStr = cmd.getOptionValue("number");
	if (nStr != null)
		fTimedIterations = Integer.parseInt(nStr);

	String wStr = cmd.getOptionValue("warmup-iterations");
	if (wStr != null)
		fWarmupIterations = Integer.parseInt(wStr);

}
 
开发者ID:ServiceNow,项目名称:stl-decomp-4j,代码行数:50,代码来源:StlPerfTest.java

示例5: testFind

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
@Test
public void testFind() throws Exception {
    File.createTempFile("temp", ".duck");
    final File f = File.createTempFile("temp", ".duck");
    File.createTempFile("temp", ".false");

    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--upload", "rackspace://cdn.cyberduck.ch/remote", f.getParent() + "/*.duck"});

    final Set<TransferItem> found = new GlobTransferItemFinder().find(input, TerminalAction.upload, new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
    assertFalse(found.isEmpty());
    assertTrue(found.contains(new TransferItem(
            new Path(new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.directory)), f.getName(), EnumSet.of(Path.Type.file)),
            new Local(f.getAbsolutePath()))));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:16,代码来源:GlobTransferItemFinderTest.java

示例6: getOptions

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
public CommandLine getOptions() {
    CommandLineParser parser = new BasicParser();
    try {
        return parser.parse(options, args, true);
    } catch (ParseException e) {
        help();
        return null;
    }

}
 
开发者ID:massivedisaster,项目名称:kickoff,代码行数:11,代码来源:Cli.java

示例7: parseGeneralOptions

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
/**
 * Parse the user-specified options, get the generic options, and modify
 * configuration accordingly
 * @param opts Options to use for parsing args.
 * @param conf Configuration to be modified
 * @param args User-specified arguments
 */
private void parseGeneralOptions(Options opts, Configuration conf, 
    String[] args) throws IOException {
  opts = buildGeneralOptions(opts);
  CommandLineParser parser = new GnuParser();
  try {
    commandLine = parser.parse(opts, preProcessForWindows(args), true);
    processGeneralOptions(conf, commandLine);
  } catch(ParseException e) {
    LOG.warn("options parsing failed: "+e.getMessage());

    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("general options are: ", opts);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:GenericOptionsParser.java

示例8: parseOption

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
private boolean parseOption(String[] args) throws ParseException {
  if (args.length == 0) return false; // no args shows help.

  CommandLineParser parser = new GnuParser();
  CommandLine cmd = parser.parse(options, args);
  if (cmd.hasOption("h")) {
    return false;
  }
  if (cmd.hasOption("execute")) upgrade = true;
  if (cmd.hasOption("check")) checkForHFileV1 = true;
  if (checkForHFileV1 && cmd.hasOption("dir")) {
    this.dirToCheckForHFileV1 = cmd.getOptionValue("dir");
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:16,代码来源:UpgradeTo96.java

示例9: main

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
/**
 * @param args Command line arguments
 * @throws InterruptedException
 */
public static void main(String[] args) throws InterruptedException {
	Options options = new Options();
	options.addOption("psk", true, "The Secret on the base of the gateway");
	options.addOption("ip", true, "The IP address of the gateway");
	options.addOption("broker", true, "MQTT URL");
	options.addOption("retained", "Topics are retained");
	options.addOption("help", "Shows this usage information");

	CommandLineParser parser = new DefaultParser();
	CommandLine cmd = null;
	try {
		cmd = parser.parse(options, args);
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	String psk = cmd.getOptionValue("psk");
	String ip = cmd.getOptionValue("ip");
	String broker = cmd.getOptionValue("broker");
	boolean retained = cmd.hasOption("retained");
	boolean help = cmd.hasOption("help");

	if (help || psk == null || ip == null || broker == null) {
		HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp("TRADFRI2MQTT", options);
		System.exit(1);
	}

	Main m = new Main(psk, ip, broker, retained);
	m.discover();
}
 
开发者ID:hardillb,项目名称:TRADFRI2MQTT,代码行数:37,代码来源:Main.java

示例10: testFindFile

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
@Test
public void testFindFile() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--delete", "rackspace://cdn.cyberduck.ch/remote"});

    assertTrue(new DeletePathFinder().find(input, TerminalAction.delete, new Path("/remote", EnumSet.of(Path.Type.file))).contains(
            new TransferItem(new Path("/remote", EnumSet.of(Path.Type.file)))
    ));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:10,代码来源:DeletePathFinderTest.java

示例11: main

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
public static void main(String[] args)
		throws ParseException, IOException, XMLStreamException, FactoryConfigurationError {
	final CommandLineParser parser = new DefaultParser();
	Options options = new Options();
	options.addOption("i", "input", true, "Input xlsx File");
	options.addOption("o", "output", true, "Output XML file");
	options.addOption("w", "workbooks", true, "optional: Workbook numbers to export 0,1,2,...,n");
	options.addOption("e", "empty", false, "optional: generate tags for empty cells");
	options.addOption("s", "single", false, "optional: export all worksheets into a single output file");
	final CommandLine cmd = parser.parse(options, args);
	E2xCmdline ex = new E2xCmdline(cmd, options);
	ex.parse();
	System.out.println("Done");

}
 
开发者ID:Stwissel,项目名称:Excel2XML,代码行数:16,代码来源:E2xCmdline.java

示例12: parseOption

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
private boolean parseOption(String[] args) throws ParseException, IOException {
  if (args.length == 0) {
    return true; // no args will process with default values.
  }
  CommandLineParser parser = new GnuParser();
  CommandLine cmd = parser.parse(options, args);
  if (cmd.hasOption("h")) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("HFileV1Detector", options, true);
    System.out
        .println("In case no option is provided, it processes hbase.rootdir using 10 threads.");
    System.out.println("Example:");
    System.out.println(" To detect any HFileV1 in a given hbase installation '/myhbase':");
    System.out.println(" $ $HBASE_HOME/bin/hbase " + this.getClass().getName() + " -p /myhbase");
    System.out.println();
    return false;
  }

  if (cmd.hasOption("p")) {
    this.targetDirPath = new Path(FSUtils.getRootDir(getConf()), cmd.getOptionValue("p"));
  }
  try {
    if (cmd.hasOption("n")) {
      int n = Integer.parseInt(cmd.getOptionValue("n"));
      if (n < 0 || n > 100) {
        LOG.warn("Please use a positive number <= 100 for number of threads."
            + " Continuing with default value " + DEFAULT_NUM_OF_THREADS);
        return true;
      }
      this.numOfThreads = n;
    }
  } catch (NumberFormatException nfe) {
    LOG.error("Please select a valid number for threads");
    return false;
  }
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:38,代码来源:HFileV1Detector.java

示例13: parseExtraArgs

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
/**
 * Parse extra arguments.
 *
 * @param args Extra arguments array
 * @throws ParseException
 */
void parseExtraArgs(String[] args) throws ParseException {
  // No-op when no extra arguments are present
  if (args == null || args.length == 0) {
    return;
  }

  // We do not need extended abilities of SqoopParser, so we're using
  // Gnu parser instead.
  CommandLineParser parser = new GnuParser();
  CommandLine cmdLine = parser.parse(getExtraOptions(), args, true);

  // Apply extra options
  if (cmdLine.hasOption(SCHEMA)) {
    String schemaName = cmdLine.getOptionValue(SCHEMA);
    LOG.info("We will use schema " + schemaName);

    this.schema = schemaName;
  }

  // Apply table hints
  if (cmdLine.hasOption(TABLE_HINTS)) {
    String hints = cmdLine.getOptionValue(TABLE_HINTS);
    LOG.info("Sqoop will use following table hints for data transfer: "
      + hints);

    this.tableHints = hints;
  }

  identityInserts = cmdLine.hasOption(IDENTITY_INSERT);
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:37,代码来源:SQLServerManager.java

示例14: MyOptions

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
private MyOptions(String args[]) {
  try {
    Options opts = buildOptions();
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(opts, args, true);
    processOptions(line, opts);
    validateOptions();
  } catch (ParseException e) {
    System.err.println(e.getMessage());
    System.err.println("Try \"--help\" option for details.");
    failed = true;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:RPCCallBenchmark.java

示例15: main

import org.apache.commons.cli.CommandLineParser; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
  CommandLineParser parser = new DefaultParser();

  // create the Options
  Options options = new Options();
  options.addOption(Option.builder("f")
          .required(true).hasArg()
          .longOpt("extra_action_file")
          .desc("bazel extra action protobuf file")
          .build());
  options.addOption(Option.builder("p")
          .required(true).hasArg()
          .longOpt("pylint_file")
          .desc("Executable pylint file to invoke")
          .build());

  try {
    // parse the command line arguments
    CommandLine line = parser.parse(options, args);

    String extraActionFile = line.getOptionValue("f");
    String pylintFile = line.getOptionValue("p");

    Collection<String> sourceFiles = getSourceFiles(extraActionFile);
    if (sourceFiles.size() == 0) {
      LOG.info("No python files found by checkstyle");
      return;
    }

    LOG.info(sourceFiles.size() + " python files found by checkstyle");

    // Create and run the command
    List<String> commandBuilder = new ArrayList<>();
    commandBuilder.add(pylintFile);
    commandBuilder.add("--rcfile=" + PYLINT_RCFILE);
    commandBuilder.add("--reports=n");
    commandBuilder.add("--disable=I");
    commandBuilder.addAll(sourceFiles);
    runLinter(commandBuilder);

  } catch (ParseException exp) {
    LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("java " + CLASSNAME, options);
  }
}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:47,代码来源:PythonCheckstyle.java


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