List of usage examples for org.apache.commons.cli HelpFormatter setSyntaxPrefix
public void setSyntaxPrefix(String prefix)
From source file:jlite.cli.ProxyDestroy.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();//w w w. ja v a2 s .c o m HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } if (line.hasOption("xml")) { System.out.println("<output>"); } run(line); } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { System.out.println("</output>"); } System.out.println(); // extra line }
From source file:jlite.cli.ProxyDelegate.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/* w w w. j a v a2 s . c om*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } if (line.hasOption("xml")) { System.out.println("<output>"); } run(line); } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if ((line != null) && (line.hasOption("xml"))) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:jlite.cli.ProxyInfo.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();//from ww w .j a v a 2s . c o m HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false); System.out.println(); // extra line System.exit(0); } if (line.hasOption("xml")) { System.out.println("<output>"); } run(line); } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:jlite.cli.JobCancel.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();//from w w w. j a v a 2s . c o m HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } else { if (line.hasOption("xml")) { System.out.println("<output>"); } run(line.getArgs(), line); } } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:jlite.cli.ProxyInit.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = setupOptions();/*from w w w . j a v a2 s . com*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { System.out.println(); // extra line helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false); System.out.println(); // extra line System.exit(0); } else { if (line.hasOption("xml")) { System.out.println("<output>"); } String[] remArgs = line.getArgs(); if (remArgs.length > 0) { run(remArgs, line); } else { throw new MissingArgumentException("Missing required argument: <voms>[:<command>]"); } } } catch (ParseException e) { System.err.println("\n" + e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if ((line != null) && (line.hasOption("xml"))) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:jlite.cli.JobMatch.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/*from w ww .j a v a 2 s .c om*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } else { if (line.hasOption("xml")) { System.out.println("<output>"); } String[] remArgs = line.getArgs(); if (remArgs.length == 1) { run(remArgs[0], line); } else if (remArgs.length == 0) { throw new MissingArgumentException("Missing required argument: <jdl_file>"); } else { throw new UnrecognizedOptionException("Unrecognized extra arguments"); } } } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:jlite.cli.JobSubmit.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/* w w w . j a va 2s . c o m*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false); System.out.println(); // extra line System.exit(0); } else { if (line.hasOption("xml")) { System.out.println("<output>"); } String[] remArgs = line.getArgs(); if (remArgs.length == 1) { run(remArgs[0], line); } else if (remArgs.length == 0) { throw new MissingArgumentException("Missing required argument: <jdl_file>"); } else { throw new UnrecognizedOptionException("Unrecognized extra arguments"); } } } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER + "\n", false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:com.nextdoor.bender.Bender.java
/** * Main entrypoint for the Bender CLI tool - handles the argument parsing and triggers the * appropriate methods for ultimately invoking a Bender Handler. * * @param args//from www. j a va 2 s . c om * @throws ParseException */ public static void main(String[] args) throws ParseException { /* * Create the various types of options that we support */ Option help = Option.builder("H").longOpt("help").desc("Print this message").build(); Option handler = Option.builder("h").longOpt("handler").hasArg() .desc("Which Event Handler do you want to simulate? \n" + "Your options are: KinesisHandler, S3Handler. \n" + "Default: KinesisHandler") .build(); Option source_file = Option.builder("s").longOpt("source_file").required().hasArg() .desc("Reference to the file that you want to process. Usage depends " + "on the Handler you chose. If you chose KinesisHandler " + "then this is a local file (file://path/to/file). If you chose " + "S3Handler, then this is the path to the file in S3 that you want to process " + "(s3://bucket/file...)") .build(); Option kinesis_stream_name = Option.builder().longOpt("kinesis_stream_name").hasArg() .desc("What stream name should we mimic? " + "Default: " + KINESIS_STREAM_NAME + " (Kinesis Handler Only)") .build(); /* * Build out the option handler and parse the options */ Options options = new Options(); options.addOption(help); options.addOption(handler); options.addOption(kinesis_stream_name); options.addOption(source_file); /* * Prepare our help formatter */ HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(100); formatter.setSyntaxPrefix("usage: BENDER_CONFIG=file://config.yaml java -jar"); /* * Parse the options themselves. Throw an error and help if necessary. */ CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (UnrecognizedOptionException | MissingOptionException | MissingArgumentException e) { logger.error(e.getMessage()); formatter.printHelp(name, options); System.exit(1); } /* * The CLI tool doesn't have any configuration files built into it. We require that the user set * BENDER_CONFIG to something reasonable. */ if (System.getenv("BENDER_CONFIG") == null) { logger.error("You must set the BENDER_CONFIG environment variable. \n" + "Valid options include: file://<file>"); formatter.printHelp(name, options); System.exit(1); } if (cmd.hasOption("help")) { formatter.printHelp(name, options); System.exit(0); } /* * Depending on the desired Handler, we invoke a specific method and pass in the options (or * defaults) required for that handler. */ String handler_value = cmd.getOptionValue(handler.getLongOpt(), KINESIS); try { switch (handler_value.toLowerCase()) { case KINESIS: invokeKinesisHandler(cmd.getOptionValue(kinesis_stream_name.getLongOpt(), KINESIS_STREAM_NAME), cmd.getOptionValue(source_file.getLongOpt())); break; case S3: invokeS3Handler(cmd.getOptionValue(source_file.getLongOpt())); break; /* * Error out if an invalid handler was supplied. */ default: logger.error("Invalid Handler Option (" + handler_value + "), valid options are: " + KINESIS); formatter.printHelp(name, options); System.exit(1); } } catch (HandlerException e) { logger.error("Error executing handler: " + e); System.exit(1); } }
From source file:ch.cyberduck.cli.TerminalHelpPrinter.java
public static void print(final Options options, final HelpFormatter formatter) { formatter.setSyntaxPrefix("Usage:"); final StringBuilder protocols = new StringBuilder(StringUtils.LF); protocols.append("Supported protocols"); protocols.append(StringUtils.LF);//from w ww .j av a 2 s .com for (Protocol p : ProtocolFactory.get().find()) { protocols.append(p.getDescription()); protocols.append(StringUtils.LF); switch (p.getType()) { case s3: case googlestorage: case swift: protocols.append("\t").append(String.format("%s://<container>/<key>", p.isBundled() ? p.getIdentifier() : p.getProvider())); break; default: protocols.append("\t").append(String.format("%s://<hostname>/<folder>/<file>", p.isBundled() ? p.getIdentifier() : p.getProvider())); break; } protocols.append(StringUtils.LF); } final StringBuilder header = new StringBuilder(StringUtils.LF); header.append("\t"); header.append("URLs must be fully qualified. Paths can either denote " + "a remote file (ftps://user@example.net/resource) or folder (ftps://user@example.net/directory/) " + "with a trailing slash. You can reference files relative to your home directory with /~ (ftps://user@example.net/~/)."); header.append(protocols.toString()); final Preferences preferences = PreferencesFactory.get(); final Local profiles = LocalFactory.get(preferences.getProperty("application.support.path"), PreferencesFactory.get().getProperty("profiles.folder.name")); header.append(StringUtils.LF); header.append(String.format("You can install additional connection profiles in %s", profiles.getAbbreviatedPath())); header.append(StringUtils.LF); final StringBuilder footer = new StringBuilder(StringUtils.LF); footer.append(String.format( "Cyberduck is libre software licenced under the GPL. For general help about using Cyberduck, please refer to %s and the wiki at %s. For bug reports or feature requests open a ticket at %s.", preferences.getProperty("website.cli"), preferences.getProperty("website.help"), MessageFormat.format(preferences.getProperty("website.bug"), preferences.getProperty("application.version")))); final License l = LicenseFactory.find(); footer.append(StringUtils.LF); if (l.verify(new DisabledLicenseVerifierCallback())) { footer.append(l.toString()); } else { footer.append("Not registered. Purchase a donation key to support the development of this software."); } formatter.printHelp("duck [options...]", header.toString(), options, footer.toString()); }
From source file:io.github.eternalbits.compactvd.CompactVD.java
private static void printHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.setSyntaxPrefix("Usage: "); final String prefix = "--"; String header = "\nTo reduce the size of dynamic disk images. Version " + version + "\n\n"; String footer = ("\nOne of ^inline, ^copy or ^dump is required. For ^inline and ^dump" + " the default options are ^drop-unused ^keep-zeroed. For ^copy the default" + " is ^drop-unused and ^drop-zeroed is implied. Not applicable arguments" + " are ignored.\n") .replace("^", prefix); formatter.setLongOptPrefix(" " + prefix); formatter.printHelp("java -jar " + jar, header, options, footer, true); }