本文整理汇总了Java中org.apache.commons.cli.BasicParser类的典型用法代码示例。如果您正苦于以下问题:Java BasicParser类的具体用法?Java BasicParser怎么用?Java BasicParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicParser类属于org.apache.commons.cli包,在下文中一共展示了BasicParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
public static void main(String[] args) throws ParseException {
Options options = new Options();
Option nameOption = new Option("n", true, "Name to resolve");
nameOption.setRequired(true);
options.addOption(nameOption);
CommandLineParser parser = new BasicParser();
CommandLine cmd = parser.parse(options, args);
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.DEBUG);
PodCIDRToNodeMapping plugin = new PodCIDRToNodeMapping();
Configuration conf = new Configuration();
plugin.setConf(conf);
String nameToResolve = cmd.getOptionValue(nameOption.getOpt());
List<String> networkPathDirs = plugin.resolve(Lists.newArrayList(nameToResolve));
log.info("Resolved " + nameToResolve + " to " + networkPathDirs);
}
示例2: parse
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
public void parse() {
CommandLineParser parser = new BasicParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args, true);
if (cmd.hasOption("h")) {
help();
} else if (cmd.hasOption("o")) {
open();
} else if (!cmd.hasOption("g")) {
log.log(Level.SEVERE, "Missing g option");
help();
}
} catch (ParseException e) {
help();
}
}
示例3: parseArguments
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
private static boolean parseArguments(String[] args) {
CommandLineParser parser = new BasicParser();
try {
CommandLine commandLine = parser.parse(OPTIONS, args);
inputPath = commandLine.getOptionValue(INPUT_PATH.getOpt());
outputPath = new Path(commandLine.getOptionValue(OUTPUT_PATH.getOpt()));
pattern = Pattern.compile(commandLine.getOptionValue(PATTERN.getOpt()));
if (commandLine.hasOption(SAMPLE_FRACTION.getOpt())) {
sampleFraction = Double.valueOf(commandLine.getOptionValue(SAMPLE_FRACTION.getOpt()));
}
if (sampleFraction < 0 || sampleFraction > 1) {
return false;
}
return true;
} catch (ParseException | IllegalArgumentException e) {
return false;
}
}
示例4: main
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Options options = createCommandLineOptions();
CommandLineParser parser = new BasicParser();
CommandLine cmdLine = null;
try {
cmdLine = parser.parse(options, args);
} catch (ParseException e) {
throw new KeywordOptimizerException("Error parsing command line parameters", e);
}
int port = Integer.parseInt(cmdLine.getOptionValue("port", DEFAULT_PORT + ""));
String contextPath = cmdLine.getOptionValue("context-path", DEFAULT_CONTEXT_PATH);
ApiServer server = new ApiServer(port, contextPath,
cmdLine.getOptionValue("kp", ""), cmdLine.getOptionValue("ap", ""));
server.start();
}
示例5: parseArgs
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
/**
* Parses the arguments passed into the program.
*
* @param args
* an array of String that contains all values passed into the
* program
* @throws ParseException
* if there is an error parsing arguments
*/
private void parseArgs(String[] args) throws ParseException {
final Options options = getCmdLineOptions();
final CommandLineParser parser = new BasicParser();
CommandLine cmd = null;
/*
* Parse the args according to the options definition. Will throw
* MissingOptionException when a required option is not specified or the
* more generic ParseException if there is any other error parsing the
* arguments.
*/
cmd = parser.parse(options, args);
if (cmd.hasOption("b")) {
setBaselinePath(cmd.getOptionValue("b"));
}
}
示例6: main
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
public static void main(String [ ] args) throws Exception {
CommandLineParser parser = new BasicParser();
Options options = getCommonRequiredOptions();
Option ingestFileOpt = OptionBuilder.withArgName(INGEST_FILE)
.hasArg()
.isRequired()
.withDescription("ingest tsv file on hdfs")
.create(INGEST_FILE);
options.addOption(ingestFileOpt);
CommandLine cmd = parser.parse( options, args);
Map<String, String> dsConf = getAccumuloDataStoreConf(cmd);
String featureName = cmd.getOptionValue(FEATURE_NAME);
SimpleFeatureType featureType = buildGDELTFeatureType(featureName);
DataStore ds = DataStoreFinder.getDataStore(dsConf);
ds.createSchema(featureType);
runMapReduceJob(featureName,
dsConf,
new Path(cmd.getOptionValue(INGEST_FILE)));
}
示例7: parse
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
/**
* Parse the given command line arguments and return the parsed representation.
*
* @param args
* @return
* @throws ParseException
*/
public static CommandLine parse(String... args) throws ParseException {
Options options = new Options();
Option help = new Option("help", "print this message");
options.addOption(help);
Option resetAdminPassword = new Option(RESET_ADMIN_PASSWORD, true, "Reset the admin password");
options.addOption(resetAdminPassword);
Option initCluster = new Option(INIT_CLUSTER, false, "Flag which can be used to initialise the first instance of a cluster.");
options.addOption(initCluster);
Option nodeName = new Option(NODE_NAME, true, "Node instance name");
options.addOption(nodeName);
Option clusterName = new Option(CLUSTER_NAME, true, "Cluster name");
options.addOption(clusterName);
Option httpPort = new Option(HTTP_PORT, true, "Server HTTP port");
options.addOption(httpPort);
CommandLineParser parser = new BasicParser();
CommandLine cmd = parser.parse(options, args);
return cmd;
}
示例8: run
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
private void run() {
try {
logger.info("Running distributedlog server : args = {}", Arrays.toString(args));
BasicParser parser = new BasicParser();
CommandLine cmdline = parser.parse(options, args);
runCmd(cmdline);
} catch (ParseException pe) {
logger.error("Argument error : {}", pe.getMessage());
printUsage();
Runtime.getRuntime().exit(-1);
} catch (IllegalArgumentException iae) {
logger.error("Argument error : {}", iae.getMessage());
printUsage();
Runtime.getRuntime().exit(-1);
} catch (ConfigurationException ce) {
logger.error("Configuration error : {}", ce.getMessage());
printUsage();
Runtime.getRuntime().exit(-1);
} catch (IOException ie) {
logger.error("Failed to start distributedlog server : ", ie);
Runtime.getRuntime().exit(-1);
}
}
示例9: main
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
public static void main(String... args) throws Exception {
Options options = new Options();
options.addOption("i", "input", true, "The file with training data.");
options.addOption("o", "output", true, "Name of trained model file.");
options.addOption("e", "epoch", true, "Number of times to go over whole training set.");
CommandLine cmd = new BasicParser().parse(options, args);
if (cmd.hasOption("i") && cmd.hasOption("o") && cmd.hasOption("e")) {
train(cmd);
log.info("Training finished.");
} else {
log.error("Invalid arguments.");
new HelpFormatter().printHelp("Train", options);
}
}
示例10: parseCommandLine
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
protected static CommandLine parseCommandLine(final String[] args,
final Options options, final String command)
throws SyncDatabaseException, ParseException {
if (args == null || options == null || command == null) {
throw new SyncDatabaseException("error.argument");
}
final CommandLineParser parser = new BasicParser();
final CommandLine commandLine = parser.parse(options, args);
if (!command.equals("help")
&& (commandLine.getArgs().length != 1 || !command
.equals(commandLine.getArgs()[0]))) {
throw new SyncDatabaseException("error.option");
}
return commandLine;
}
示例11: parseArguments
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
private static void parseArguments(String[] args, Properties props) {
// read command line arguments
HelpFormatter helpFormater = new HelpFormatter();
helpFormater.setWidth(Integer.MAX_VALUE);
CommandLineParser cmdParser = new BasicParser();
cmdOptions = new Options();
setupArgumentOptions();
// parse arguments
try {
cmd = cmdParser.parse(cmdOptions, args);
if (cmd.hasOption('h')) {
helpFormater.printHelp("OSM GPX MAP MATCHER", cmdOptions, true);
System.exit(0);
}
assignArguments(props);
} catch (ParseException parseException) {
LOGGER.info(parseException.getMessage());
helpFormater.printHelp("OSM GPX MAP MATCHER", cmdOptions);
System.exit(1);
}
}
示例12: parseArguments
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
private static void parseArguments(String[] args, Properties props) {
// read command line arguments
HelpFormatter helpFormater = new HelpFormatter();
helpFormater.setWidth(Integer.MAX_VALUE);
CommandLineParser cmdParser = new BasicParser();
cmdOptions = new Options();
setupArgumentOptions();
// parse arguments
try {
cmd = cmdParser.parse(cmdOptions, args);
if (cmd.hasOption('h')) {
helpFormater.printHelp("OSM GPX INCLINE CALCULATOR", cmdOptions, true);
System.exit(0);
}
assignArguments(props);
} catch (ParseException parseException) {
LOGGER.info(parseException.getMessage());
helpFormater.printHelp("OSM GPX INCLINE CALCULATOR", cmdOptions);
System.exit(1);
}
}
示例13: parseArguments
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
private static void parseArguments(String[] args, Properties props) {
// read command line arguments
HelpFormatter helpFormater = new HelpFormatter();
helpFormater.setWidth(Integer.MAX_VALUE);
CommandLineParser cmdParser = new BasicParser();
cmdOptions = new Options();
setupArgumentOptions();
// parse arguments
try {
cmd = cmdParser.parse(cmdOptions, args);
if (cmd.hasOption('h')) {
helpFormater.printHelp("OSM GPX Preprocessor", cmdOptions, true);
System.exit(0);
}
assignArguments(props);
} catch (ParseException parseException) {
LOGGER.info(parseException.getMessage());
helpFormater.printHelp("OSM GPX MAP MATCHER", cmdOptions);
System.exit(1);
}
}
示例14: ReadCmd
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
private void ReadCmd(String[] args) throws ParseException {
Options options = new Options();
// Add Possible Options
options.addOption("I", "Input File", true, "The absolue file path of the input file.");
options.addOption("O", "Output File", true, "The absolue file path of the output file.");
CommandLineParser parser = new BasicParser();
CommandLine line = parser.parse(options, args);
if (line.hasOption("I")) {
inFile = line.getOptionValue("I");
}
if (line.hasOption("O")) {
outFile = line.getOptionValue("O");
}
}
示例15: ReadCmd
import org.apache.commons.cli.BasicParser; //导入依赖的package包/类
public void ReadCmd(String[] args) throws ParseException {
Options options = new Options();
// Add Possible Options
options.addOption("I", "Input Path", true, "The absolue path of the input file or directory.");
options.addOption("O", "Output Path", true, "The absolue path of the output file or directory.");
CommandLineParser parser = new BasicParser();
CommandLine line = parser.parse(options, args);
if (line.hasOption("I")) {
inPath = line.getOptionValue("I");
}
if (line.hasOption("O")) {
outPath = line.getOptionValue("O");
}
}