Java Code Examples for org.apache.commons.cli.HelpFormatter#setOptionComparator()

The following examples show how to use org.apache.commons.cli.HelpFormatter#setOptionComparator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmdOptions.java    From cloudsync with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: StateStoreBasedWatermarkStorageCli.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
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);
  }
 
Example 3
Source File: PublicMethodsCliObjectFactory.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
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);
  }
 
Example 4
Source File: ActiveOptionProcessor.java    From ofexport2 with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: ParametersHelper.java    From vsphere-automation-sdk-java with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: RankPL.java    From RankPL with MIT License 5 votes vote down vote up
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);
}
 
Example 7
Source File: JumbuneAgent.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: CliProcessor.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** 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());
}
 
Example 9
Source File: PropertyLoader.java    From InflatableDonkey with MIT License 5 votes vote down vote up
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);
}
 
Example 10
Source File: ProtostuffCompilerCli.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: SolrSnapshotsTool.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: AbstractHalyardTool.java    From Halyard with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: KeywordOptimizer.java    From keyword-optimizer with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 14
Source File: SimpleNBodySimulationCS257.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: CLI.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 16
Source File: CommandLineArguments.java    From zserio with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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("");
}
 
Example 17
Source File: CWLExecLauncher.java    From cwlexec with Apache License 2.0 4 votes vote down vote up
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);
}