org.apache.commons.cli.HelpFormatter#setOptionComparator ( )源码实例Demo

下面列出了org.apache.commons.cli.HelpFormatter#setOptionComparator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Prints the usage information for running the sample
 */
public void printUsage(String sampleName) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(new Comparator<Option>() {
        @Override
        public int compare(Option option1, Option option2) {
            return 0;
        }

    });
    formatter.printHelp(150,
        "\njava -cp target/vsphere-samples-7.0.0.1.jar " + sampleName,
        "\nSample Options:",
        getOptions(new ArrayList<Option>(this.optionMap.keySet())),
        "",
        true);
    System.exit(0);
}
 
源代码2 项目: ofexport2   文件: ActiveOptionProcessor.java
@SuppressWarnings("unchecked")
public void printHelp() throws IOException {

    System.out.println (progName.toUpperCase());
    System.out.println();

    try (
        InputStream in = this.getClass().getResourceAsStream("/version.properties")) {
        Properties p = new Properties();
        p.load(in);
        System.out.println ("Version: " + p.getProperty("version"));
        System.out.println ("Build Date: " + p.getProperty("date"));

    }

    System.out.println();

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);
    // Output in the order I specify
    formatter.setOptionComparator((x, y) -> ((ActiveOption<P>) x).getOrder() - ((ActiveOption<P>) y).getOrder());
    formatter.printHelp(progName, options);
}
 
private void printUsage(String usage, Options options) {

    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(new Comparator<Option>() {
      @Override
      public int compare(Option o1, Option o2) {
        if (o1.isRequired() && !o2.isRequired()) {
          return -1;
        }
        if (!o1.isRequired() && o2.isRequired()) {
          return 1;
        }
        return o1.getOpt().compareTo(o2.getOpt());
      }
    });

    formatter.printHelp(usage, options);
  }
 
private void printUsage(Options options) {

    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(new Comparator<Option>() {
      @Override
      public int compare(Option o1, Option o2) {
        if (o1.isRequired() && !o2.isRequired()) {
          return -1;
        }
        if (!o1.isRequired() && o2.isRequired()) {
          return 1;
        }
        return o1.getOpt().compareTo(o2.getOpt());
      }
    });

    String usage = "gobblin watermarks ";
    formatter.printHelp(usage, options);
  }
 
源代码5 项目: cloudsync   文件: CmdOptions.java
public void printHelp()
{
	final HelpFormatter formatter = new HelpFormatter();
	formatter.setWidth(120);
	formatter.setOptionComparator(new Comparator<Option>()
	{

		@Override
		public int compare(Option o1, Option o2)
		{
			if (positions.indexOf(o1) < positions.indexOf(o2)) return -1;
			if (positions.indexOf(o1) > positions.indexOf(o2)) return 1;
			return 0;
		}
	});
	// formatter.setOptPrefix("");
	formatter.printHelp("cloudsync <options>", options);
}
 
源代码6 项目: zserio   文件: CommandLineArguments.java
/**
 * Prints help.
 */
public void printHelp()
{
    final HelpFormatter hf = new HelpFormatter();

    hf.setSyntaxPrefix("Usage: ");
    hf.setLeftPadding(2);
    hf.setOptionComparator(null);
    hf.printHelp("java -jar zserio.jar <options> zserioInputFile\n", "Options:", options, null, false);
    ZserioToolPrinter.printMessage("");
}
 
源代码7 项目: Cognizant-Intelligent-Test-Scripter   文件: CLI.java
static void help() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setDescPadding(0);
    formatter.setOptionComparator(null);
    System.out.println("CLI\n"
            + "Invoke command line options  for retrieving execution details, setting variable, change settings etc.");
    formatter.printHelp("\nRun.bat", LookUp.OPTIONS, true);
}
 
源代码8 项目: scava   文件: SimpleNBodySimulationCS257.java
private static void wrongArguments(final Options options, ParseException e) {
	// oops, something went wrong
	System.err.println("Some of the arguments where missing or wrong: " + e.getMessage());
	// automatically generate the help statement
	HelpFormatter formatter = new HelpFormatter();
	formatter.setOptionComparator(null);
	formatter.printHelp("java -jar stars.jar", "\nN-body Simulation of Stars\n", options,
			"\nEnjoY!.",
			true);
}
 
源代码9 项目: keyword-optimizer   文件: KeywordOptimizer.java
/**
 * Prints the help screen.
 *
 * @param options the expected command line parameters
 */
private static void printHelp(Options options) {
  // Automatically generate the help statement.
  HelpFormatter formatter = new HelpFormatter();
  formatter.setWidth(LINE_MAX_WIDTH);

  // Comparator to show non-argument options first.
  formatter.setOptionComparator(new Comparator<Option>() {
    @Override
    public int compare(Option o1, Option o2) {
      if (o1.hasArg() && !o2.hasArg()) {
        return 1;
      }
      if (!o1.hasArg() && o2.hasArg()) {
        return -1;
      }

      return o1.getOpt().compareTo(o2.getOpt());
    }
  });

  System.out.println("Keyword Optimizer - BETA");
  System.out.println("------------------------");
  System.out.println();
  System.out.println("This utility can be used creating a optimizing and finding a set of "
      + "'good' keywords. It uses the TargetingIdeaService / \n"
      + "TrafficEstimatorService of the AdWords API to first obtain a set "
      + "of seed keywords and then perform a round-based \nprocess for "
      + "optimizing them.");
  System.out.println();
  formatter.printHelp("keyword-optimizer", options);
  System.out.println();
}
 
源代码10 项目: Halyard   文件: AbstractHalyardTool.java
protected final void printHelp() {
    HelpFormatter hf = new HelpFormatter();
    hf.setOptionComparator(new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            if (o1 instanceof OrderedOption && o2 instanceof OrderedOption) return ((OrderedOption)o1).order - ((OrderedOption)o2).order;
            else return 0;
        }
    });
    hf.printHelp(100, "halyard " + name, header, options, footer, true);
}
 
源代码11 项目: lucene-solr   文件: SolrSnapshotsTool.java
private static void printHelp(Options options) {
  StringBuilder helpFooter = new StringBuilder();
  helpFooter.append("Examples: \n");
  helpFooter.append("snapshotscli.sh --create snapshot-1 -c books -z localhost:2181 \n");
  helpFooter.append("snapshotscli.sh --list -c books -z localhost:2181 \n");
  helpFooter.append("snapshotscli.sh --describe snapshot-1 -c books -z localhost:2181 \n");
  helpFooter.append("snapshotscli.sh --export snapshot-1 -c books -z localhost:2181 -b repo -l backupPath -i req_0 \n");
  helpFooter.append("snapshotscli.sh --delete snapshot-1 -c books -z localhost:2181 \n");

  HelpFormatter formatter = new HelpFormatter();
  formatter.setOptionComparator(new OptionComarator<>());
  formatter.printHelp("SolrSnapshotsTool", null, options, helpFooter.toString(), false);
}
 
源代码12 项目: RankPL   文件: RankPL.java
private static void printUsage() {
	HelpFormatter formatter = new HelpFormatter();
	formatter.setWidth(160);
	List<String> order = Arrays.asList("source", "r", "t", "c", "d", "m", "f", "ns", "nr", "help");
	formatter.setOptionComparator(new Comparator<Option>() {
		@Override
		public int compare(Option o1, Option o2) {
			String s1 = ((Option) o1).getOpt();
			String s2 = ((Option) o2).getOpt();
			return order.indexOf(s1) - order.indexOf(s2);
		}
	});
	formatter.printHelp("java -jar RankPL.jar", createOptions(), true);
}
 
private void printHelp(Options options) {
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(79);
    formatter.setOptionComparator(Comparator.comparingInt(this::getOptionOrder));
    formatter.printHelp("protostuff-compiler [options] proto_files", options);
}
 
源代码14 项目: InflatableDonkey   文件: PropertyLoader.java
void help(Collection<? extends Option> optionList, String header, String footer, String cmdLineSyntax) {
    Options options = new Options();
    optionList.forEach(options::addOption);

    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setOptionComparator(null);
    helpFormatter.printHelp(
            cmdLineSyntax,
            header,
            options,
            footer);
}
 
源代码15 项目: contribution   文件: CliProcessor.java
/** Prints the usage information. */
public static void printUsage() {
    final HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator(null);
    formatter.printHelp("\njava -jar releasenotes-builder-[version]-all.jar [options]",
        buildOptions());
}
 
源代码16 项目: jumbune   文件: JumbuneAgent.java
private static void displayOptions(Options options) {
	HelpFormatter formatter = new HelpFormatter();
	formatter.setOptionComparator(null);
	formatter.setWidth(80);
	formatter.printHelp("java -jar <jumbune jar file>.jar", options, true);
	exitVM(0);
}
 
源代码17 项目: cwlexec   文件: CWLExecLauncher.java
private void printHelp() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setOptionComparator((o1, o2) -> optionIndex.get(o1) - optionIndex.get(o2));
    formatter.printHelp(200, ResourceLoader.getMessage("cwl.command.usage"), null, options, null);
}