List of usage examples for org.apache.commons.cli HelpFormatter printHelp
public void printHelp(int width, String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)
options
with the specified command line syntax. From source file:jlite.cli.ProxyInit.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = setupOptions();// w w w . j a 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")) { 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:edu.ksu.cis.indus.xmlizer.JimpleXMLizerCLI.java
/** * The entry point to execute this xmlizer from command prompt. * /*from w w w . j a v a2s.c o m*/ * @param s is the command-line arguments. * @throws RuntimeException when jimple xmlization fails. * @pre s != null */ public static void main(final String[] s) { final Scene _scene = Scene.v(); final Options _options = new Options(); Option _o = new Option("d", "dump directory", true, "The directory in which to write the xml files. " + "If unspecified, the xml output will be directed standard out."); _o.setArgs(1); _o.setArgName("path"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("h", "help", false, "Display message."); _options.addOption(_o); _o = new Option("p", "soot-classpath", true, "Prepend this to soot class path."); _o.setArgs(1); _o.setArgName("classpath"); _o.setOptionalArg(false); _options.addOption(_o); final HelpFormatter _help = new HelpFormatter(); try { final CommandLine _cl = (new BasicParser()).parse(_options, s); final String[] _args = _cl.getArgs(); if (_cl.hasOption('h')) { final String _cmdLineSyn = "java " + JimpleXMLizerCLI.class.getName() + "<options> <class names>"; _help.printHelp(_cmdLineSyn.length(), _cmdLineSyn, "", _options, "", true); } else { if (_args.length > 0) { if (_cl.hasOption('p')) { _scene.setSootClassPath( _cl.getOptionValue('p') + File.pathSeparator + _scene.getSootClassPath()); } final NamedTag _tag = new NamedTag("JimpleXMLizer"); for (int _i = 0; _i < _args.length; _i++) { final SootClass _sc = _scene.loadClassAndSupport(_args[_i]); _sc.addTag(_tag); } final IProcessingFilter _filter = new TagBasedProcessingFilter(_tag.getName()); writeJimpleAsXML(new Environment(_scene), _cl.getOptionValue('d'), null, new UniqueJimpleIDGenerator(), _filter); } else { System.out.println("No classes were specified."); } } } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }