Java 类org.kohsuke.args4j.OptionHandlerFilter 实例源码

项目:jacoco-toolbox    文件:Tool.java   
/**
 * Parses the tool' arguments
 *
 * @param args
 *          Arguments to parse.
 */
protected void parseArgs(final String[] args) {
  final CmdLineParser parser = new CmdLineParser(this);
  try {
    parser.parseArgument(args);
  } catch (final CmdLineException e) {
    parser.printUsage(stderr);
    exit("Failed to parse args", e);
  }

  if (help) {
    // User asked for help screen
    parser.printUsage(stderr);
    stderr.println();
    stderr.print(parser.printExample(OptionHandlerFilter.REQUIRED));
    exit(0);
  }
}
项目:closure-compiler    文件:CommandLineRunner.java   
private void printCategoryUsage(
    String categoryName,
    final Collection<String> options,
    OutputStreamWriter outputStream,
    String prefix,
    String suffix) {

  try {
    if (prefix != null) {
      printStringLineWrapped(prefix, outputStream);
    }

    outputStream.write(boldPrefix + categoryName + ":\n" + normalPrefix);

    parser.printUsage(
        outputStream,
        null,
        new OptionHandlerFilter() {
          @Override
          public boolean select(OptionHandler optionHandler) {
            if (optionHandler.option instanceof NamedOptionDef) {
              return !optionHandler.option.hidden()
                  && options.contains(
                      ((NamedOptionDef) optionHandler.option).name().replaceFirst("^--", ""));
            }
            return false;
          }
        });

    if (suffix != null) {
      printStringLineWrapped(suffix, outputStream);
    }
  } catch (IOException e) {
    // Ignore.
  }
}
项目:dir-analyzer    文件:DirAnalyzer.java   
private boolean checkParameters(String[] args) {
    CmdLineParser parser = new CmdLineParser(this);

       parser.setUsageWidth(80);

       try {
           // parse the arguments.
           parser.parseArgument(args);

           if(!Constants.JSON_OUTPUT_FORMAT.equals(fileExtension) && !Constants.XML_OUTPUT_FORMAT.equals(fileExtension)){
            throw new CmdLineException(parser,"Output format should be either 'xml' or 'json'");
           }
           if(scanDifferenceFilePath != null){
            generateDiff = true;
           }

           if(!generateDiff && fullScanResultFilePath == null){
            throw new CmdLineException(parser,"You need to specify at least one expected result '-d' and/or '-f' options");
           }


       }catch(CmdLineException e) {
           // if there's a problem in the command line,
           // you'll get this exception. this will report
           // an error message.
        Logger.error(e.getMessage());
        Logger.error("java -jar "+Constants.APPLICATION_NAME+" [options...] arguments...");
           // print the list of available options
           parser.printUsage(System.err);
           Logger.error("");

           // print option sample. This is useful some time
           Logger.error(" Example: java -jar "+Constants.APPLICATION_NAME+parser.printExample(OptionHandlerFilter.ALL));

           return false;
       }    
       return true;
}
项目:es6draft    文件:Repl.java   
private static String getUsageString(CmdLineParser parser, boolean showAll) {
    ResourceBundle rb = getResourceBundle();
    StringWriter writer = new StringWriter();
    writer.write(formatMessage(rb, "usage", getVersionString(), PROGRAM_NAME));
    parser.printUsage(writer, rb, showAll ? OptionHandlerFilter.ALL : OptionHandlerFilter.PUBLIC);
    return writer.toString();
}
项目:s3mper    文件:FileSystemVerifyCommand.java   
@Override
public void execute(Configuration conf, String[] args) throws Exception {
    CmdLineParser parser = new CmdLineParser(this);

    String keyId = conf.get("fs.s3n.awsAccessKeyId");
    String keySecret = conf.get("fs.s3n.awsSecretAccessKey");

    s3 = new AmazonS3Client(new BasicAWSCredentials(keyId, keySecret));

    try {
        parser.parseArgument(args);

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        List<Future> futures = new ArrayList<Future>();

        BufferedReader fin = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));

        try {
            for(String line = fin.readLine(); line != null; line = fin.readLine()) {
                futures.add(executor.submit(new FileCheckTask(new Path(line.trim()))));
            }
        } finally {
            fin.close();
        }

        for(Future f : futures) {
            f.get();
        }

        executor.shutdown();
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println("s3mper fs verify [options]");
        // print the list of available options
        parser.printUsage(System.err);
        System.err.println();

        System.err.println(" Example: s3mper fs verify "+parser.printExample(OptionHandlerFilter.ALL));
    }
}
项目:s3mper    文件:MetastoreTimeseriesDeleteCommand.java   
@Override
public void execute(Configuration conf, String[] args) throws Exception {
    CmdLineParser parser = new CmdLineParser(this);

    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println("s3mper meta delete_ts [options]");
        // print the list of available options
        parser.printUsage(System.err);
        System.err.println();

        System.err.println(" Example: s3mper meta delete_ts "+parser.printExample(OptionHandlerFilter.ALL));

        return;
    }

    MetastoreJanitor janitor = new MetastoreJanitor();
    janitor.initalize(PathUtil.S3N, conf);
    janitor.setScanLimit(readUnits);
    janitor.setDeleteLimit(writeUnits);
    janitor.setScanThreads(scanThreads);
    janitor.setDeleteThreads(deleteThreads);

    janitor.deleteTimeseries(TimeUnit.valueOf(unitType.toUpperCase()), unitCount);
}
项目:s3mper    文件:MetastorePathDeleteCommand.java   
@Override
public void execute(Configuration conf, String[] args) throws Exception {
    CmdLineParser parser = new CmdLineParser(this);

    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println("java SampleMain [options...] arguments...");
        // print the list of available options
        parser.printUsage(System.err);
        System.err.println();

        System.err.println(" Example: s3mper metastore "+parser.printExample(OptionHandlerFilter.ALL));

        return;
    }

    MetastoreJanitor janitor = new MetastoreJanitor();
    janitor.initalize(PathUtil.S3N, conf);
    janitor.setScanLimit(readUnits);
    janitor.setDeleteLimit(writeUnits);
    janitor.setScanThreads(scanThreads);
    janitor.setDeleteThreads(deleteThreads);

    janitor.deletePaths(TimeUnit.valueOf(unitType.toUpperCase()), unitCount);
}
项目:jstuart    文件:SimpleBot.java   
public void doMain(String[] args) throws IOException {

        CmdLineParser parser = new CmdLineParser(this);

        // if you have a wider console, you could increase the value;
        // here 80 is also the default
        parser.setUsageWidth(80);

        try {
            // parse the arguments.
            parser.parseArgument(args);

        } catch (CmdLineException e) {
            // if there's a problem in the command line,
            // you'll get this exception. this will report
            // an error message.
            System.err.println(e.getMessage());
            System.err.println("java SimpleBot [options...] arguments...");
            // print the list of available options
            parser.printUsage(System.err);
            System.err.println();

            // print option sample. This is useful some time
            System.err.println("  Example: java SampleMain" + parser.printExample(OptionHandlerFilter.REQUIRED));

            return;
        }


        OkHttpClient client = new OkHttpClient();
        final MMBot bot = MMBot.logIn(client, this.mattermostServer, this.login, this.pwd);

        for (String bugzilla : bugzillas) {
            bot.onMessage(new RespondWithBugzillaReferences(bugzilla));
        }

        for (String gerrit : gerrits) {
            bot.onMessage(new RespondWithGerritReferences(gerrit));
        }

        if (twitterAccessToken != null && twitterAccessTokenSecret != null && twitterConsumerKey != null
                && twitterConsumerSecret != null) {
            ConfigurationBuilder cb = new ConfigurationBuilder();

            cb.setOAuthConsumerKey(this.twitterConsumerKey).setOAuthConsumerSecret(this.twitterConsumerSecret)
                    .setOAuthAccessToken(this.twitterAccessToken)
                    .setOAuthAccessTokenSecret(this.twitterAccessTokenSecret);
            TwitterFactory tf = new TwitterFactory(cb.build());
            Twitter twitter = tf.getInstance();
            bot.onMessage(new RespondWithTwitterReferences(twitter));
        }

        bot.onMessage(new RespondWithGiphyAnimation());
        bot.onMessage(new RespondWithPullRequestsReferences());

        bot.listen();

    }