List of usage examples for org.apache.commons.cli MissingOptionException printStackTrace
public void printStackTrace(PrintStream s)
From source file:org.apache.felix.ipojo.task.IPojoc.java
/** * The main entry point/* w w w . j av a2 s . com*/ * @param args the arguments */ public static void main(String[] args) { Options options = buildOptions(); CommandLine cmd = null; try { cmd = buildCommandLine(args, options); if (cmd.hasOption('h')) { printHelp(options); } else { IPojoc compiler = new IPojoc(); compiler.execute(cmd); } } catch (MissingOptionException e) { for (String opt : (List<String>) e.getMissingOptions()) { System.err.println("The '" + opt + "' option is missing"); } printHelp(options); } catch (MissingArgumentException e) { System.err.println("The option '" + e.getOption() + "' requires an argument"); printHelp(options); } catch (Exception e) { System.out.printf("Manipulation failed: %s%n", e.getMessage()); if ((cmd != null) && cmd.hasOption('X')) { e.printStackTrace(System.out); } else { System.out.printf("Use -X option to print the full stack trace%n"); } } }
From source file:org.codehaus.continuum.cli.ContinuumCC.java
public int work(String[] args) throws Exception { if (embedder == null) { throw new ContinuumException("Must be started first."); }/*from w ww .java 2s.c o m*/ commands = plexus.lookupMap(CliCommand.ROLE); if (args.length == 0) { throw new Exception("The first argument on the command line must be the command name."); } String commandName = args[0]; CliCommand command = getCommand(commandName); try { // Remove the first argument which is the command name. List argsList = new ArrayList(Arrays.asList(args)); argsList.remove(0); args = (String[]) argsList.toArray(new String[args.length - 1]); command.execute(args); } catch (MissingOptionException ex) { System.err.println(ex.getMessage()); System.err.println(command.getCommandLineHelp()); return -1; } catch (UnrecognizedOptionException ex) { System.err.println(ex.getMessage()); System.err.println(command.getCommandLineHelp()); return -1; } catch (ContinuumException ex) { ex.printStackTrace(System.out); return -1; } return 0; }