/** * 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); }
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(); } }
/** 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); }