List of usage examples for org.apache.commons.cli HelpFormatter setSyntaxPrefix
public void setSyntaxPrefix(String prefix)
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);/*w ww.ja v a2 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.eucalyptus.upgrade.TestHarness.java
@SuppressWarnings({ "static-access" }) private static void printHelp(Options opts) { try {/*from w w w .j av a 2s. c o m*/ PrintWriter out = new PrintWriter(System.out); HelpFormatter help = new HelpFormatter(); help.setArgName("TESTS"); help.printHelp(out, LINE_BYTES, "java -jar test.jar", "Options controlling the test harness.", opts, 2, 4, "", true); Multimap<Class, Method> testMethods = getTestMethods(); help = new HelpFormatter(); help.setLongOptPrefix(""); help.setOptPrefix(""); help.setSyntaxPrefix(""); help.setLeftPadding(0); Options testOptions = new Options(); for (Class c : testMethods.keySet()) { testOptions.addOption( OptionBuilder.withDescription(getDescription(c)).withLongOpt(c.getSimpleName()).create()); for (Method m : testMethods.get(c)) { testOptions.addOption(OptionBuilder.withDescription(getDescription(m)) .withLongOpt(c.getSimpleName() + "." + m.getName()).create()); } } help.printHelp(out, LINE_BYTES, " ", "Tests:", testOptions, 0, 2, "", false); out.flush(); } catch (Exception e) { System.out.println(e); System.exit(1); } }
From source file:com.msbmsb.genealogeo.ui.cli.GenealoGeoCLI.java
/** * Display usage message//from w w w . j av a2 s. co m */ public void usage(String msg) { HelpFormatter hf = new HelpFormatter(); PrintWriter pw = new PrintWriter(System.err); hf.setSyntaxPrefix("Usage: "); hf.printHelp(pw, hf.getWidth(), this.usage, null, this.opts, hf.getLeftPadding(), hf.getDescPadding(), msg, false); pw.flush(); System.exit(1); }
From source file:eu.stratosphere.myriad.driver.MyriadDriverFrontend.java
private void printHelp(PrintStream out) { PrintWriter pw = new PrintWriter(out); int width = 80; int leftPad = 0; int descPad = 2; HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix("Usage: "); formatter.printHelp(pw, width, getUsage(), "\nAvailable Options:\n \n", this.options, leftPad, descPad, null, false);/*w w w. j a va 2 s. c om*/ pw.flush(); }
From source file:com.sqs.tq.fdc.config.CmdLineConfig.java
public void showUsage(PrintStream out) { PrintWriter pw = new PrintWriter(out); HelpFormatter hf = new HelpFormatter(); hf.setSyntaxPrefix("Usage:" + hf.getNewLine()); // @formatter:off hf.printHelp(pw, 80,// w w w . j av a 2 s . c om " " + PROG_NAME + printOption(CmdLineOption.HELP) + hf.getNewLine() + " " + PROG_NAME + printOption(CmdLineOption.DIR) + printOption(CmdLineOption.NAME) + hf.getNewLine() + " " + PROG_NAME + printOption(CmdLineOption.FILE) + hf.getNewLine(), "Analyze the distribution of a file a directory (recursive) or analyze a single file.", runOptions, 2, 3, "Please report issues at https://github.com/sqs-dach/file-distribution-checker", false); // @formatter:on pw.close(); }
From source file:lu.uni.adtool.tools.Clo.java
/** * Print usage information//from w w w .ja va 2 s. co m */ private void help() { // This prints out some help HelpFormatter formater = new HelpFormatter(); formater.setSyntaxPrefix(Options.getMsg("clo.usage.txt") + " "); String header = Options.getMsg("clo.header.txt"); String footer = Options.getMsg("clo.footer.txt", getUsageName()); // * formatter.printHelp("myapp", header, options, footer, true); formater.printHelp(getUsageName() + " ", header, options, footer, true); }
From source file:com.axelor.shell.core.Target.java
public void showHelp() { Options options = getOptions();/*from w w w . j a v a 2s .co m*/ HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix("Usage: "); formatter.setWidth(80); String cmdLine = cliCommand.name() + " " + cliCommand.usage(); String header = cliCommand.help(); String footer = cliCommand.notes(); if (!header.endsWith("\n")) { header = header + "\n"; } if (footer != null && footer.trim().length() > 0 && !footer.startsWith("\n")) { footer = "\n" + footer; } formatter.printHelp(cmdLine, header, options, footer); }
From source file:cz.pecina.retro.ondra.CommandLineProcessor.java
private void usage() { final HelpFormatter usage = new HelpFormatter(); usage.setSyntaxPrefix(Application.getString(this, "help.usage")); usage.printHelp("java -jar ondra.jar [OPTION] ...", options); }
From source file:cz.pecina.retro.pmi80.CommandLineProcessor.java
private void usage() { final HelpFormatter usage = new HelpFormatter(); usage.setSyntaxPrefix(Application.getString(this, "help.usage")); usage.printHelp("java -jar pmi80.jar [OPTION] ...", options); }
From source file:cz.pecina.retro.pmd85.CommandLineProcessor.java
private void usage() { final HelpFormatter usage = new HelpFormatter(); usage.setSyntaxPrefix(Application.getString(this, "help.usage")); usage.printHelp("java -jar pmd85.jar [OPTION] ...", options); }