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


Java BasicParser类代码示例

本文整理汇总了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);
}
 
开发者ID:apache-spark-on-k8s,项目名称:kubernetes-HDFS,代码行数:19,代码来源:PodCIDRToNodeMapping.java

示例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();
    }
}
 
开发者ID:massivedisaster,项目名称:kickoff,代码行数:21,代码来源:Cli.java

示例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;
    }
}
 
开发者ID:comdirect,项目名称:hadoop-logfile-inputformat,代码行数:22,代码来源:Sample.java

示例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();
}
 
开发者ID:googleads,项目名称:keyword-optimizer,代码行数:19,代码来源:ApiServer.java

示例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"));
    }
}
 
开发者ID:openmainframeproject,项目名称:ade,代码行数:27,代码来源:AdeAnalysisOutputCompare.java

示例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)));
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:24,代码来源:GDELTIngest.java

示例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;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:33,代码来源:MeshCLI.java

示例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);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:24,代码来源:DistributedLogServerApp.java

示例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);
    }
}
 
开发者ID:wmeddie,项目名称:dl4j-trainer-archetype,代码行数:19,代码来源:Train.java

示例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;
}
 
开发者ID:ossc-db,项目名称:syncdb,代码行数:19,代码来源:SyncDatabase.java

示例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);
    }
}
 
开发者ID:GIScience,项目名称:osmgpxmapmatcher,代码行数:22,代码来源:Main.java

示例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);
    }
}
 
开发者ID:GIScience,项目名称:osmgpxinclinecalculator,代码行数:22,代码来源:Main.java

示例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);
    }
}
 
开发者ID:GIScience,项目名称:osmgpxpreprocessor,代码行数:22,代码来源:Main.java

示例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");
        }
    }
 
开发者ID:OMNILab,项目名称:ArubaSyslog,代码行数:19,代码来源:StartProcessing.java

示例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");
    }
}
 
开发者ID:OMNILab,项目名称:ArubaSyslog,代码行数:19,代码来源:StartBatchProcessing.java


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