@Override
 public void run(
     ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value)
     throws ArgumentParserException {
   parser.printVersion();
   System.exit(0);
 }
示例#2
0
 /**
  * Runs the command line interface given some arguments.
  *
  * @param arguments the command line arguments
  * @return whether or not the command successfully executed
  * @throws Exception if something goes wrong
  */
 public boolean run(String... arguments) throws Exception {
   try {
     if (isFlag(HELP, arguments)) {
       parser.printHelp(stdOut);
     } else if (isFlag(VERSION, arguments)) {
       parser.printVersion(stdOut);
     } else {
       final Namespace namespace = parser.parseArgs(arguments);
       if (namespace.get("is-help") == null) {
         final Command command = commands.get(namespace.getString(COMMAND_NAME_ATTR));
         command.run(bootstrap, namespace);
       }
     }
     return true;
   } catch (ArgumentParserException e) {
     // TODO: 5/25/13 <coda> -- make ArgumentParser#handleError not depend on System.err
     stdErr.println(e.getMessage());
     e.getParser().printHelp(stdErr);
     return false;
   } catch (ConfigurationException e) {
     // TODO: 7/26/13 <ntelford> -- as above, this probably shouldn't depend on System.err
     stdErr.println(e.getMessage());
     return false;
   }
 }