Exemple #1
0
 public static void main(String[] args) {
   CreateUser action = new CreateUser();
   try {
     Args.parse(action, args);
     action.execute();
   } catch (IllegalArgumentException e) {
     Args.usage(action);
   } catch (Exception e) {
     System.out.println("!!! FAILURE !!!");
     e.printStackTrace();
   }
 }
  /**
   * Parse command line, create hive input
   *
   * @param args Command line arguments
   * @return Parsed arguments
   */
  private static Optional<BenchmarkArgs> handleCommandLine(String[] args) {
    BenchmarkArgs parsedArgs = new BenchmarkArgs();
    try {
      Args.parse(parsedArgs, args);
    } catch (IllegalArgumentException e) {
      System.err.println("ERROR: " + e);
      Args.usage(parsedArgs);
      return Optional.absent();
    }
    if (parsedArgs.isHelp()) {
      Args.usage(parsedArgs);
      return Optional.absent();
    }

    return Optional.of(parsedArgs);
  }
  /**
   * Run the correct entry point.
   *
   * @param args command line arguments.
   */
  public void babysit(String[] args) {
    try {
      Args.parse(p, args);
    } catch (IllegalArgumentException e) {
      System.err.println(e.getMessage());
      helpAndDie(1);
    }

    CliHandler requestHandler = null;

    if (p.help) {
      helpAndDie(0);
    } else if (p.exports) {
      requestHandler = exportHandler;
    } else if (p.version) {
      requestHandler = versionHandler;
    } else if (p.status) {
      requestHandler = statusHandler;
    } else if (p.fetch) {
      requestHandler = fetchHandler;
    } else if (p.publish) {
      requestHandler = publishHandler;
    } else if (p.delete != null) {
      requestHandler = deleteHandler;
    } else {
      helpAndDie(0);
    }

    requestHandler.handle();
  }
Exemple #4
0
 /** Returns true if the arguments can be parsed correctly */
 protected boolean parseArguments(
     @NotNull PrintStream errStream, @NotNull A arguments, @NotNull String[] args) {
   try {
     arguments.freeArgs = Args.parse(arguments, args);
     return true;
   } catch (IllegalArgumentException e) {
     usage(errStream);
   } catch (Throwable t) {
     // Always use tags
     errStream.println(MessageRenderer.TAGS.renderException(t));
   }
   return false;
 }
Exemple #5
0
 /** Allow derived classes to add additional command line arguments */
 protected void usage(@NotNull PrintStream target) {
   // We should say something like
   //   Args.usage(target, K2JVMCompilerArguments.class);
   // but currently cli-parser we are using does not support that
   // a corresponding patch has been sent to the authors
   // For now, we are using this:
   PrintStream oldErr = System.err;
   System.setErr(target);
   try {
     // TODO: use proper argv0
     Args.usage(createArguments());
   } finally {
     System.setErr(oldErr);
   }
 }
 /**
  * Show the help and stop the application.
  *
  * @param exitCode of the application.
  */
 private void helpAndDie(int exitCode) {
   Args.usage(p);
   System.exit(exitCode);
 }