/**
   * *************************************************************************** {@link Runnable}
   * Interface **************************************************************************
   */
  public void run(String[] args) throws IOException {

    if (needsHelp(args)) {
      printHelp();
      System.exit(0);
    }

    try {
      CommandLine cli = _parser.parse(_options, args, true);
      runApplication(cli, args);
    } catch (MissingOptionException ex) {
      System.err.println("Missing argument: " + ex.getMessage());
      printHelp();
    } catch (MissingArgumentException ex) {
      System.err.println("Missing argument: " + ex.getMessage());
      printHelp();
    } catch (UnrecognizedOptionException ex) {
      System.err.println("Unknown argument: " + ex.getMessage());
      printHelp();
    } catch (AlreadySelectedException ex) {
      System.err.println("Argument already selected: " + ex.getMessage());
      printHelp();
    } catch (ParseException ex) {
      System.err.println(ex.getMessage());
      printHelp();
    } catch (TransformSpecificationException ex) {
      System.err.println("error with transform line: " + ex.getLine());
      System.err.println(ex.getMessage());
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 2
0
 void parseCommandLine(String[] args) {
   // @formatter:on
   CommandLineParser parser = new DefaultParser();
   try {
     commandline = parser.parse(options, args);
   } catch (AlreadySelectedException ase) {
     help(CliBase.InvalidCommandLine, "Already Selected: " + ase.getOption());
   } catch (AmbiguousOptionException aoe) {
     help(CliBase.InvalidCommandLine, "Ambiguous Option: " + aoe.getMatchingOptions());
   } catch (MissingArgumentException mae) {
     help(CliBase.InvalidCommandLine, "Missing Argument: " + mae.getOption());
   } catch (MissingOptionException moe) {
     help(CliBase.InvalidCommandLine, "Missing Option: " + moe.getMissingOptions());
   } catch (UnrecognizedOptionException uoe) {
     help(CliBase.InvalidCommandLine, "Unrecongnized Option: " + uoe.getOption());
   } catch (Exception e) {
     help(CliBase.InvalidCommandLine, "Unexpected Exception: " + e.getClass().getName());
   }
   if (commandline.hasOption(CliBase.HelpShortCl)) help(0, null);
   if (commandline.hasOption(CliBase.VersionShortCl)) cliBase.version();
 }