Java 类org.apache.commons.cli.BasicParser 实例源码

项目:kubernetes-HDFS    文件:PodCIDRToNodeMapping.java   
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);
}
项目:kickoff    文件:Cli.java   
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();
    }
}
项目:hadoop-logfile-inputformat    文件:Sample.java   
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;
    }
}
项目:keyword-optimizer    文件:ApiServer.java   
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();
}
项目:ade    文件:AdeAnalysisOutputCompare.java   
/**
 * 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"));
    }
}
项目:geomesa-tutorials    文件:GDELTIngest.java   
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)));
}
项目:mesh    文件:MeshCLI.java   
/**
 * 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;
}
项目:distributedlog    文件:DistributedLogServerApp.java   
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);
    }
}
项目:dl4j-trainer-archetype    文件:Train.java   
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);
    }
}
项目:syncdb    文件:SyncDatabase.java   
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;
}
项目:osmgpxmapmatcher    文件:Main.java   
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);
    }
}
项目:osmgpxinclinecalculator    文件:Main.java   
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);
    }
}
项目:osmgpxpreprocessor    文件:Main.java   
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);
    }
}
项目:ArubaSyslog    文件:StartProcessing.java   
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");
        }
    }
项目:ArubaSyslog    文件:StartBatchProcessing.java   
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");
    }
}
项目:edits    文件:RunExperiment.java   
public static void main(String[] args) throws Exception {
    System.setProperty("log4j.defaultInitOverride", "true");
    LogManager.resetConfiguration();
    ConsoleAppender ca = new ConsoleAppender(new PatternLayout("%-5p - %m%n"));
    ca.setName("edits");
    LogManager.getRootLogger().addAppender(ca);
    Options ops = new Options();
    ops.addOption("optimize", false, "");
    ops.addOption("balance", false, "");
    ops.addOption("rules", false, "");
    ops.addOption("debug", false, "");
    ops.addOption("wordnet", true, "");

    CommandLine commandLine = new BasicParser().parse(ops, args);

    if (!commandLine.hasOption("debug"))
        ca.setThreshold(Level.INFO);

    RunExperiment res = new RunExperiment(commandLine.getArgs()[0], commandLine.hasOption("balance"),
            commandLine.hasOption("optimize"), commandLine.hasOption("rules"));

    if (commandLine.hasOption("wordnet"))
        res.setRulesSource(new WordnetRulesSource(commandLine.getOptionValue("wordnet")));

    res.train(commandLine.getArgs()[1]);
}
项目:osmgpxfilter    文件:Main.java   
private static void parseArguments(String[] args) {
    // 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("GPX Filter", cmdOptions, true);
            System.exit(0);
        }
        assignArguments(cmd);
    } catch (ParseException parseException) {
        LOGGER.info(parseException.getMessage());
        helpFormater.printHelp("GPX Filter", cmdOptions);
        System.exit(1);
    }
}
项目:spring-usc    文件:CommandLineArgumentParser.java   
public static CommandLine parse(String args[], Options options, String commandName)
{
    CommandLineParser parser = new BasicParser();
     CommandLine cl = null;
    try {
        /**
         * PARSE THE COMMAND LINE ARGUMENTS *
         */
        cl = parser.parse(options, args);
        if (cl == null || cl.getOptions().length == 0 || cl.hasOption("help")) {
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp(commandName, options);
            return null;
        }

} catch (Exception e) {
    logger.error("Error occured while parsing arguments!", e);
    return cl;
}
    return cl;
}
项目:dig-elasticsearch    文件:BulkLoadSequenceFile.java   
public static CommandLine parse(String args[], Options options, String commandName)
{
    CommandLineParser parser = new BasicParser();
    CommandLine cl = null;
    try {
        cl = parser.parse(options, args);
        if (cl == null || cl.getOptions().length == 0 || cl.hasOption("help")) {
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp(commandName, options);
            return null;
        }

    } catch (Exception e) {

        return cl;
    }
    return cl;
}
项目:dig-elasticsearch    文件:ScanAndScroll.java   
public static CommandLine parse(String args[], Options options, String commandName)
{
    CommandLineParser parser = new BasicParser();
     CommandLine cl = null;
    try {
        /**
         * PARSE THE COMMAND LINE ARGUMENTS *
         */
        cl = parser.parse(options, args);
        if (cl == null || cl.getOptions().length == 0 || cl.hasOption("help")) {
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp(commandName, options);
            return null;
        }

} catch (Exception e) {
    LOG.error("Error occured while parsing arguments!", e);
    return cl;
}
    return cl;
}
项目:jfiler    文件:ServerConfig.java   
public static ServerConfig parseArgs(String[] args) {
    Options options = CLIOptionsProcessor.process(ServerConfig.class);
    try {
        CommandLine cli = new BasicParser().parse(options, args);
        if (cli.hasOption('h'))//show help
            throw new Exception();
        String strPort = cli.getOptionValue('p');
        ServerConfig server = new ServerConfig(strPort == null ? Const.DEFAULT_SERVER_PORT : Integer.parseInt(strPort),
                new File(cli.getOptionValue('d')),
                cli.getOptionValue('k'));
        if (server.checkConfig())
            return server;
    } catch (Exception e) {
        new HelpFormatter().printHelp("java -jar jfiler.jar S[erver] [OPTIONS]", options, false);
        System.exit(0);
    }
    return null;
}
项目:jfiler    文件:ClientConfig.java   
public static ClientConfig parseArgs(String[] args) {
    Options options = CLIOptionsProcessor.process(ClientConfig.class);
    try {
        CommandLine cli = new BasicParser().parse(options, args);
        if (cli.hasOption('h'))//show help
            throw new Exception();
        String[] hostOption = cli.getOptionValues('H');
        return new ClientConfig(hostOption[0],
                hostOption.length > 1 ? Integer.parseInt(hostOption[1]) : Const.DEFAULT_SERVER_PORT,
                cli.getOptionValue('k'));
    } catch (Exception e) {
        new HelpFormatter().printHelp("java -jar jfiler.jar C[lient] [OPTIONS]", options, false);
        System.exit(0);
    }
    return null;
}
项目:hibernate-conventions    文件:MappingGeneratorTool.java   
public static void main(String[] args) throws Exception {

        Options options = new Options();
        options.addOption("o", true, "output file (default: target/classes/META-INF/mapping.xml)");

        CommandLine cl = new BasicParser().parse(options, args);

        if (cl.hasOption("h") || args.length == 0) {
            new HelpFormatter().printHelp(
                    "java " + MappingGeneratorTool.class.getName() + " [packages]",
                    options);
        } else {

            String output = cl.getOptionValue("o", "target/classes/META-INF/mapping.xml");
            FileOutputStream out = ConventionUtils.createFile(output);

            try {
                new MappingGeneratorTool(cl.getArgs()).generate(out);
            } finally {
                ConventionUtils.closeIfNotNull(out);
            }

        }

    }
项目:dbmigrate    文件:Main.java   
private void run(String[] args) {
    Options options = this.createOptions();

    String subCommand = null;
    if (args.length < 1) {
        this.printHelp(options);
    } 

    CommandLineParser commandParser = new BasicParser();
    CommandLine commandLine = null;
    try {
        String[] opts = new String[args.length - 1];
        /* array shift */
        System.arraycopy(args, 1, opts, 0, args.length - 1);
        commandLine = commandParser.parse(options, opts, false);
    } catch (ParseException e) {
        log.error(e.getMessage());
        this.printHelp(options);
    }

    subCommand = args[0];
    this.dispatchCommand(options, commandLine, subCommand);
}
项目:postman-runner    文件:PostmanCollectionRunner.java   
public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(ARG_COLLECTION, true, "File name of the POSTMAN collection.");
    options.addOption(ARG_ENVIRONMENT, true, "File name of the POSTMAN environment variables.");
    options.addOption(ARG_FOLDER, true,
            "(Optional) POSTMAN collection folder (group) to execute i.e. \"My Use Cases\"");
    options.addOption(ARG_HALTONERROR, false, "(Optional) Stop on first error in POSTMAN folder.");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);
    String colFilename = cmd.getOptionValue(ARG_COLLECTION);
    String envFilename = cmd.getOptionValue(ARG_ENVIRONMENT);
    String folderName = cmd.getOptionValue(ARG_FOLDER);
    boolean haltOnError = cmd.hasOption(ARG_HALTONERROR);

    if (colFilename == null || colFilename.isEmpty() || envFilename == null || envFilename.isEmpty()) {
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("postman-runner", options);
        return;
    }

    PostmanCollectionRunner pcr = new PostmanCollectionRunner();
    pcr.runCollection(colFilename, envFilename, folderName, haltOnError);
}
项目:TopicExplorer    文件:CommandLineParser.java   
/**
 * Adds the possible arguments. Sets global args and executes the parsing of the given arguments.
 * 
 * @param args
 * @throws ParseException
 *             if there are any problems encountered while parsing the command line tokens.
 */
public CommandLineParser(String[] args) {
    options = new Options();
    options.addOption("h", "help", false, "prints information about passing arguments.");
    options.addOption("c", "catalog", true, "determines location of catalog file");
    options.getOption("c").setArgName("string");
    options.addOption("g", "graph", false, "only the graph is drawed");
    options.addOption("s", "start", true, "set commands to start with, separated by only comma");
    options.getOption("s").setArgName("string");
    options.addOption("e", "end", true, "set commands to end with, separated only by comma");
    options.getOption("e").setArgName("string");

    commandLineParser = new BasicParser();
    commandLine = null;
    helpFormatter = new HelpFormatter();

    this.args = args;

    parseArguments();
}
项目:digidoc4j    文件:DigiDoc4J.java   
private static void run(String[] args) {
  Options options = createParameters();

  try {
    CommandLine commandLine = new BasicParser().parse(options, args);
    if (commandLine.hasOption("version")) {
      showVersion();
    }
    if (shouldManipulateContainer(commandLine)) {
      execute(commandLine);
    }
    if (!commandLine.hasOption("version") && !shouldManipulateContainer(commandLine)) {
      showUsage(options);
    }
  } catch (ParseException e) {
    logger.error(e.getMessage());
    showUsage(options);
  }
}
项目:yangtools    文件:Main.java   
private static CommandLine parseArguments(final String[] args, final Options options,
        final HelpFormatter formatter) {
    final CommandLineParser parser = new BasicParser();

    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (final ParseException e) {
        LOG.error("Failed to parse command line options.", e);
        printHelp(options, formatter);

        System.exit(1);
    }

    return cmd;
}
项目:Sql4D    文件:Main.java   
private static void defineOptions() {
    options.addOption("bh", "broker_host", true, "Druid broker node hostname/Ip");
    options.addOption("bp", "broker_port", true, "Druid broker node port");
    options.addOption("ch", "coordinator_host", true, "Druid coordinator node hostname/Ip");
    options.addOption("cp", "coordinator_port", true, "Druid coordinator node port");
    options.addOption("oh", "overlord_host", true, "Druid overlord node hostname/Ip");
    options.addOption("op", "overlord_port", true, "Druid overlord node port");
    options.addOption("mh", "mysql_host", true, "Druid MySql hostname/Ip");
    options.addOption("mp", "mysql_port", true, "Druid MySql node port");
    options.addOption("mid", "mysql_id", true, "Druid MySql user Id");
    options.addOption("mpw", "mysql_passwd", true, "Druid MySql password");
    options.addOption("mdb", "mysql_dbname", true, "Druid MySql db name");
    options.addOption("pp", "proxy_port", true, "Druid proxy node port");
    options.addOption("i", "history", true, "Number of commands in history");
    options.addOption("hh", "http_headers", true, "Http Headers if any to pass");
    parser = new BasicParser();
}
项目:cantilever    文件:Configuration.java   
public void getConfigFile(String[] args) {
    Options opt = new Options();
    Option op = new Option("config", true,
            "Full path to config file: /opt/cantilever/cantilever.config");
    op.setRequired(true);
    opt.addOption(op);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd;

    try {
        cmd = parser.parse(opt, args);
        ConfigurationSingleton.instance.readConfigFile(cmd
                .getOptionValue("config"));

    } catch (ParseException pe) {
        usage(opt);
    }
}
项目:raml-tester-proxy    文件:ServerOptionsParser.java   
@Override
protected ServerOptions parse(String[] args) throws ParseException {
    final CommandLine cmd = new BasicParser().parse(createOptions(), expandArgs(args));

    validate(cmd);

    final int port = parsePort(cmd);
    final String target = cmd.getOptionValue('t');
    final File mockDir = parseMockDir(cmd);
    final String ramlUri = cmd.getOptionValue('r');
    final String baseUri = parseBaseUri(cmd.getOptionValue('b'));
    final boolean ignoreXheaders = cmd.hasOption('i');
    final File saveDir = parseSaveDir(cmd.getOptionValue('s'));
    final ReportFormat fileFormat = parseReportFormat(cmd.getOptionValue('f'));
    final boolean asyncMode = cmd.hasOption('a');
    final int[] delay = parseDelay(cmd.getOptionValue('d'));
    final ValidatorConfigurator validatorConfigurator = parseValidator(cmd.hasOption('v'), cmd.getOptionValue('v'));
    return new ServerOptions(port, target, mockDir, ramlUri, baseUri, saveDir, fileFormat, ignoreXheaders, asyncMode, delay[0], delay[1], validatorConfigurator);
}
项目:udidb    文件:ConfigBuilder.java   
/**
 * Builds the configuration for udidb from the command line parameters
 *
 * @param args the command line arguments
 *
 * @return the configuration
 *
 * @throws ParseException if the configuration cannot be created due to invalid parameters
 * @throws HelpMessageRequested when the user requests the help message
 */
public Config build(String[] args) throws ParseException, HelpMessageRequested {

    CommandLineParser parser = new BasicParser();

    CommandLine commandLine = parser.parse(options, args);

    if ( commandLine.hasOption(helpOption.getOpt()) ) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("udidb", options, true);
        throw new HelpMessageRequested();
    }

    // TODO convert options to config

    return new CommandLineConfigImpl();
}
项目:KassandraMRHelper    文件:WriteSampleSSTable.java   
/**
 * Called to validate the parameters.
 *
 * @param args
 * @throws ParseException
 */
private static void buildParametersFromArgs(String[] args) throws ParseException {
    CommandLineParser cliParser = new BasicParser();
    Options options = buildOptions();
    CommandLine cli = cliParser.parse(options, args);
    if (cli.getArgs().length < 1 || cli.hasOption('h')) {
        printUsage(options);
    }
    tableDirectory = new File(cli.getArgs()[0] +
                              String.format("/%s/%s/", KEYSPACE_NAME, COLUMN_FAMILY_NAME));
    tableDirectory.mkdirs();
    numberOfStudents = Integer.parseInt(cli.getOptionValue('s',
            String.valueOf(DEFAULT_NUM_STUDENTS)));
    eventsPerStudent = Integer.parseInt(cli.getOptionValue('e',
            String.valueOf(DEFAULT_NUM_EVENTS_PER_STUDENT)));

}
项目:segan    文件:RegressionBenchmark.java   
public static void main(String[] args) {
    try {
        parser = new BasicParser(); // create the command line parser
        options = new Options(); // create the Options
        addExperimentOptions();
        cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            CLIUtils.printHelp(getHelpString(RegressionBenchmark.class.getName()), options);
            return;
        }
        verbose = cmd.hasOption("v");
        debug = cmd.hasOption("d");
        runExperiment();
        System.out.println("End time: " + getCompletedTime());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:segan    文件:SHLDAOld.java   
public static void run(String[] args) {
    try {
        parser = new BasicParser(); // create the command line parser
        options = new Options(); // create the Options
        addOptions();
        cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            CLIUtils.printHelp(getHelpString(), options);
            return;
        }

        if (cmd.hasOption("cv-folder")) {
            runCrossValidation();
        } else {
            runModel();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Use option -help for all options.");
    }
}
项目:segan    文件:SLDA.java   
public static void run(String[] args) {
    try {
        parser = new BasicParser(); // create the command line parser
        options = new Options(); // create the Options
        addOptions();
        cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            CLIUtils.printHelp(getHelpString(), options);
            return;
        }
        runModel();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Use option -help for all options.");
    }
}
项目:segan    文件:SHLDA.java   
public static void run(String[] args) {
    try {
        parser = new BasicParser(); // create the command line parser
        options = new Options(); // create the Options
        addOptions();
        cmd = parser.parse(options, args);
        if (cmd.hasOption("help")) {
            CLIUtils.printHelp(getHelpString(), options);
            return;
        }
        if (cmd.hasOption("cv-folder")) {
            runCrossValidation();
        } else {
            runModel();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Use option -help for all options.");
    }
}
项目:Wikipedia-Corpus-Converter    文件:WikiI5Converter.java   
public void run(String[] args) throws I5Exception  {

    CommandLineParser parser = new BasicParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        throw new I5Exception(e);
    }

    String xmlFolder = cmd.getOptionValue("x");
    String type = cmd.getOptionValue("t");
    String dumpFilename = cmd.getOptionValue("w");
    String outputFile = cmd.getOptionValue("o");        
    String encoding = cmd.getOptionValue("e");              
    String inflectives = cmd.getOptionValue("inf");
    String index = cmd.getOptionValue("i");

    convert(xmlFolder, type, dumpFilename, inflectives, encoding, outputFile, index);

}
项目:hotpgen    文件:Main.java   
private static HotpGenArguments parseCommandLine(String[] args) {
    Options options = new Options();
    options.addOption("k", "key", true, "the key (provide once - it is encrypted in properties file)");
    options.addOption("p", "password", true, "optional password for stronger encryption in the properties file");

    HotpGenArguments commandLineArgs = new HotpGenArguments();

    try {
        CommandLine cmd = new BasicParser().parse(options, args);
        if (cmd.getArgs().length != 0) {
            throw new ParseException("Unrecognized argument: " + cmd.getArgs()[0]);
        }
        commandLineArgs.key = cmd.getOptionValue("k");
        commandLineArgs.password = cmd.getOptionValue("p");
    } catch (ParseException e) {
        System.out.println("Parsing command line failed - " + e.getMessage() );
        new HelpFormatter().printHelp("hotpgen", options);
    }

    return commandLineArgs;
}
项目:tapestry5-cli    文件:CLIParserImpl.java   
public CLIParserImpl(Logger logger,
        ApplicationConfigurationSource applicationBeanSource,
        Validator validator, CLIValidator cliValidator, String commandName,
        BridgeCLIOptionProvider bridgeCLIOptionProvider,
        Collection<CLIOption> _options) {

    this.logger = logger;
    this.validator = validator;
    this.cliValidator = cliValidator;
    this.applicationConfigurationSource = applicationBeanSource;

    this.commandName = commandName;

    this.bridgeCLIOptionProvider = bridgeCLIOptionProvider;

    this.formatter = new HelpFormatter();
    this.pw = new PrintWriter(System.out);
    this.parser = new BasicParser();

    validateAndMerge(_options);
}