List of usage examples for org.apache.commons.cli HelpFormatter setOptionComparator
public void setOptionComparator(Comparator comparator)
From source file:com.esri.geoevent.test.performance.ProducerMain.java
private static void printHelp(Options performerOptions) { HelpFormatter formatter = new HelpFormatter(); formatter.setLongOptPrefix("-"); formatter.setArgName("value"); formatter.setWidth(100);//w w w . j a v a 2s .c o m // do not sort the options in any order formatter.setOptionComparator(new Comparator<Option>() { @Override public int compare(Option o1, Option o2) { return 0; } }); formatter.printHelp(ImplMessages.getMessage("PRODUCER_EXECUTOR_HELP_TITLE_MSG"), performerOptions, true); System.out.println(""); }
From source file:com.milaboratory.mitcr.cli.Main.java
public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override/*from w w w . ja va 2s . c o m*/ public int compare(Option o1, Option o2) { return Integer.compare(orderingMap.get(o1.getOpt()), orderingMap.get(o2.getOpt())); } }); final String executable = System.getProperty("executable", "java -jar mitcr.jar"); err.println("usage: " + executable + " -pset <preset name> [options] input_file output_file.cls"); err.println(" " + executable + " -pset <preset name> [options] input_file output_file.txt"); err.println(" " + executable + " -pset <preset name> [options] -export newPresetName"); err.println(); formatter.printOptions(new PrintWriter(err, true), 85, options, 2, 3); err.println(); }
From source file:io.werval.cli.DamnSmallDevShell.java
private static void printHelp(Options options, PrintWriter out) { HelpFormatter help = new HelpFormatter(); help.setOptionComparator(new OptionsComparator()); help.printUsage(out, WIDTH, "io.werval.cli [options] [command(s)]"); out.print("\n" + " The Damn Small Werval DevShell\n" + " - do not manage dependencies ;\n" + " - do not allow you to extend the build ;\n" + " - do not assemble applications.\n"); help.printWrapped(out, WIDTH, 2,//w w w .ja v a 2s . c o m "\n" + "Meaning you have to manage your application dependencies and assembly yourself. " + "Theses limitations make this DevShell suitable for quick prototyping only. " + "Prefer the Gradle or Maven build systems integration."); out.println("\n io.werval.cli is part of the Werval Development Kit - http://werval.io"); out.println("\n" + "Commands:\n\n" + " new <appdir> Create a new skeleton application in the 'appdir' directory.\n" + " secret Generate a new application secret.\n" + " clean Delete devshell temporary directory, see 'tmpdir' option.\n" + " devshell Run the Application in development mode.\n" + " start Run the Application in production mode.\n" + "\n" + " If no command is specified, 'start' is assumed."); out.println("\n" + "Options:" + "\n"); help.printOptions(out, WIDTH, options, 2, 2); help.printWrapped(out, WIDTH, 2, "\n" + "All paths are relative to the current working directory, " + "except if they are absolute of course."); help.printWrapped(out, WIDTH, 2, "\n" + "Licensed under the Apache License Version 2.0, http://www.apache.org/licenses/LICENSE-2.0"); out.println(); }
From source file:de.adrianwilke.acotspjava.Parse.java
static int parse_commandline(String args[]) { // TODO range check if (args.length == 0) { System.err.println("No options are specified."); System.err.println("Try `--help' for more information."); System.exit(1);/*from www .jav a 2 s .c o m*/ } Options options = new Options(); options.addOption("r", "tries", true, "# number of independent trials"); options.addOption("s", "tours", true, "# number of steps in each trial"); options.addOption("t", "time", true, "# maximum time for each trial"); options.addOption("seed", true, "# seed for the random number generator"); options.addOption("i", "tsplibfile", true, "f inputfile (TSPLIB format necessary)"); options.addOption("o", "optimum", true, "# stop if tour better or equal optimum is found"); options.addOption("m", "ants", true, "# number of ants"); options.addOption("g", "nnants", true, "# nearest neighbours in tour construction"); options.addOption("a", "alpha", true, "# alpha (influence of pheromone trails)"); options.addOption("b", "beta", true, "# beta (influence of heuristic information)"); options.addOption("e", "rho", true, "# rho: pheromone trail evaporation"); options.addOption("q", "q0", true, "# q_0: prob. of best choice in tour construction"); options.addOption("c", "elitistants", true, "# number of elitist ants"); options.addOption("f", "rasranks", true, "# number of ranks in rank-based Ant System"); options.addOption("k", "nnls", true, "# No. of nearest neighbors for local search"); options.addOption("l", "localsearch", true, "0:no local search 1:2-opt 2:2.5-opt 3:3-opt"); options.addOption("d", "dlb", false, "1 use don't look bits in local search"); options.addOption("u", "as", false, "apply basic Ant System"); options.addOption("v", "eas", false, "apply elitist Ant System"); options.addOption("w", "ras", false, "apply rank-based version of Ant System"); options.addOption("x", "mmas", false, "apply MAX-MIN ant_colony system"); options.addOption("y", "bwas", false, "apply best-worst ant_colony system"); options.addOption("z", "acs", false, "apply ant_colony colony system"); options.addOption("quiet", false, "reduce output to a minimum, no extra files"); options.addOption("h", "help", false, "display this help text and exit"); CommandLine cmd = null; CommandLineParser parser = new BasicParser(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix("Usage: "); formatter.setOptionComparator(new OptComparator()); formatter.printHelp(InOut.PROG_ID_STR + " [OPTION]... [ARGUMENT]...", "Options:", options, ""); System.exit(0); } System.out.println("OPTIONS:"); if (cmd.hasOption("quiet")) { InOut.quiet_flag = true; System.out.println("-quiet Quiet mode is set"); } if (cmd.hasOption("t")) { InOut.max_time = Float.parseFloat(cmd.getOptionValue("t")); System.out.println("-t/time Time limit with argument " + InOut.max_time); } else { System.out.println("Note: Time limit is set to default " + InOut.max_time + " seconds"); } if (cmd.hasOption("r")) { InOut.max_tries = Integer.parseInt(cmd.getOptionValue("r")); System.out.println("-r/tries Number of tries with argument " + InOut.max_tries); } else { System.out.println("Note: Number of tries is set to default " + InOut.max_tries); } if (cmd.hasOption("s")) { InOut.max_tours = Integer.parseInt(cmd.getOptionValue("s")); System.out.println("-s/tours Maximum number tours with argument " + InOut.max_tours); } else { System.out.println("Note: Maximum number tours is set to default " + InOut.max_tours); } if (cmd.hasOption("seed")) { Utilities.seed = Integer.parseInt(cmd.getOptionValue("seed")); System.out.println("-seed with argument " + Utilities.seed); } else { System.out.println("Note: A seed was generated as " + Utilities.seed); } if (cmd.hasOption("o")) { InOut.optimal = Integer.parseInt(cmd.getOptionValue("o")); System.out.println("-o/optimum Optimal solution with argument " + InOut.optimal); } else { System.out.println("Note: Optimal solution value is set to default " + InOut.optimal); } if (cmd.hasOption("i")) { InOut.name_buf = cmd.getOptionValue("i"); System.out.println("-i/tsplibfile File with argument " + InOut.name_buf); } else { System.err.println("Error: No input file given"); System.exit(1); } // Choice of ONE algorithm int algorithmCount = 0; if (cmd.hasOption("u")) { algorithmCount++; } if (cmd.hasOption("w")) { algorithmCount++; } if (cmd.hasOption("x")) { algorithmCount++; } if (cmd.hasOption("v")) { algorithmCount++; } if (cmd.hasOption("y")) { algorithmCount++; } if (cmd.hasOption("z")) { algorithmCount++; } if (algorithmCount > 1) { System.err.println("Error: More than one ACO algorithm enabled in the command line."); System.exit(1); } else if (algorithmCount == 1) { Ants.as_flag = false; Ants.eas_flag = false; Ants.ras_flag = false; Ants.mmas_flag = false; Ants.bwas_flag = false; Ants.acs_flag = false; } if (cmd.hasOption("u")) { Ants.as_flag = true; InOut.set_default_as_parameters(); System.out.println("-u/as is set, run basic Ant System"); } if (cmd.hasOption("v")) { Ants.eas_flag = true; InOut.set_default_eas_parameters(); System.out.println("-v/eas is set, run Elitist Ant System"); } if (cmd.hasOption("w")) { Ants.ras_flag = true; InOut.set_default_ras_parameters(); System.out.println("-w/ras is set, run Rank-based Ant System"); } if (cmd.hasOption("x") || algorithmCount == 0) { Ants.mmas_flag = true; InOut.set_default_mmas_parameters(); System.out.println("-x/mmas is set, run MAX-MIN Ant System"); } if (cmd.hasOption("y")) { Ants.bwas_flag = true; InOut.set_default_bwas_parameters(); System.out.println("-y/bwas is set, run Best-Worst Ant System"); } if (cmd.hasOption("z")) { Ants.acs_flag = true; InOut.set_default_acs_parameters(); System.out.println("-z/acs is set, run Ant Colony System"); } // Local search if (cmd.hasOption("l")) { LocalSearch.ls_flag = Integer.parseInt(cmd.getOptionValue("l")); switch (LocalSearch.ls_flag) { case 0: System.out.println("Note: local search flag is set to default 0 (disabled)"); break; case 1: System.out.println("Note: local search flag is set to default 1 (2-opt)"); break; case 2: System.out.println("Note: local search flag is set to default 2 (2.5-opt)"); break; case 3: System.out.println("Note: local search flag is set to default 3 (3-opt)"); break; default: System.out.println("-l/localsearch with argument " + LocalSearch.ls_flag); break; } } if (LocalSearch.ls_flag != 0) { InOut.set_default_ls_parameters(); } if (cmd.hasOption("m")) { Ants.n_ants = Integer.parseInt(cmd.getOptionValue("m")); System.out.println("-m/ants Number of ants with argument " + Ants.n_ants); } else { System.out.println("Note: Number of ants is set to default " + Ants.n_ants); } if (cmd.hasOption("a")) { Ants.alpha = Float.parseFloat(cmd.getOptionValue("a")); System.out.println("-a/alpha with argument " + Ants.alpha); } else { System.out.println("Note: Alpha is set to default " + Ants.alpha); } if (cmd.hasOption("b")) { Ants.beta = Float.parseFloat(cmd.getOptionValue("b")); System.out.println("-b/beta with argument " + Ants.beta); } else { System.out.println("Note: Beta is set to default " + Ants.beta); } if (cmd.hasOption("e")) { Ants.rho = Float.parseFloat(cmd.getOptionValue("e")); System.out.println("-e/rho with argument " + Ants.rho); } else { System.out.println("Note: Rho is set to default " + Ants.rho); } if (cmd.hasOption("q")) { Ants.q_0 = Float.parseFloat(cmd.getOptionValue("q")); System.out.println("-q/q0 with argument " + Ants.q_0); } else { System.out.println("Note: q0 is set to default " + Ants.q_0); } if (cmd.hasOption("c")) { Ants.elitist_ants = Integer.parseInt(cmd.getOptionValue("c")); System.out.println("-c/elitistants Number of elitist ants with argument " + Ants.elitist_ants); } else { System.out.println("Note: Number of elitist ants is set to default " + Ants.elitist_ants); } if (cmd.hasOption("f")) { Ants.ras_ranks = Integer.parseInt(cmd.getOptionValue("f")); System.out.println("-f/rasranks Number of ranks with argument " + Ants.ras_ranks); } else { System.out.println("Note: Number of ranks is set to default " + Ants.ras_ranks); } if (cmd.hasOption("k")) { LocalSearch.nn_ls = Integer.parseInt(cmd.getOptionValue("k")); System.out.println("-k/nnls Number nearest neighbours with argument " + LocalSearch.nn_ls); } else { System.out.println( "Note: Number nearest neighbours in local search is set to default " + LocalSearch.nn_ls); } if (cmd.hasOption("d")) { LocalSearch.dlb_flag = true; System.out.println("-d/dlb Don't-look-bits flag with argument " + LocalSearch.dlb_flag); } else { System.out.println("Note: Don't-look-bits flag is set to default " + LocalSearch.dlb_flag); } return 0; }
From source file:com.github.codingtogenomic.CodingToGenomic.java
private static void showHelp(Options o, String msg, Integer exitVal) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptionComparator()); formatter.setLeftPadding(8);/*w ww . j a v a2 s .c o m*/ formatter.setWidth(80); if (msg != null) { System.out.println("\nERROR: " + msg); } formatter.printHelp("CodingToGenomic " + "[-g <gene>] [-c <coordinate>] [options]\n", o, false); System.out.println(""); System.exit(exitVal); }
From source file:com.google.api.ads.adwords.keywordoptimizer.KeywordOptimizer.java
/** * Prints the help screen./*ww w . ja v a 2 s . c om*/ * * @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(); }
From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java
public void printHelp(PrintWriter stream, String usage, String header, String footer) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override/*from w w w.j av a 2s. c o m*/ public int compare(Option opt1, Option opt2) { return (int) Math.signum(optionsOrder.get(opt1.getOpt()) - optionsOrder.get(opt2.getOpt())); } }); formatter.printHelp(stream, HelpFormatter.DEFAULT_WIDTH, usage, header, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer); }
From source file:guru.nidi.ramlproxy.cli.OptionsParser.java
public void showHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(80);//from w w w . j av a 2s. com formatter.setOptionComparator(optionComparator()); formatter.printHelp("java -jar raml-tester-standalone.jar", helpHeader(), createOptions(), "", true); }
From source file:ch.cern.db.flume.sink.kite.util.InferSchemaFromTable.java
public void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override/* w w w .ja v a 2 s . c o m*/ public int compare(Option o1, Option o2) { if (o1.isRequired()) return -1; if (o2.isRequired()) return 1; return 0; } }); formatter.setWidth(150); formatter.printHelp("./infer-avro-schema-from-database.sh", options, true); }
From source file:com.github.horrorho.inflatabledonkey.args.PropertyLoader.java
public void help(Collection<? extends Option> optionList) { Options options = new Options(); optionList.forEach(options::addOption); HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setOptionComparator(null); helpFormatter.printHelp(/*from w w w . j a v a 2 s . c o m*/ Property.APP_NAME.value().orElse("") + " [OPTION]... (<token> | <appleid> <password>) ", options); }