本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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()))));
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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)))
));
}
示例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");
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
}