Ejemplo n.º 1
0
 public ShellCommand lookupCommand(String discriminator, List<Token> tokens) throws CLIException {
   List<ShellCommand> collectedTable = commandsByName(discriminator);
   // reduction
   List<ShellCommand> reducedTable = new ArrayList<ShellCommand>();
   for (ShellCommand cs : collectedTable) {
     if (cs.getMethod().getParameterTypes().length == tokens.size() - 1
         || (cs.getMethod().isVarArgs()
             && (cs.getMethod().getParameterTypes().length <= tokens.size() - 1))) {
       reducedTable.add(cs);
     }
   }
   // selection
   if (collectedTable.size() == 0) {
     throw CLIException.createCommandNotFound(discriminator);
   } else if (reducedTable.size() == 0) {
     throw CLIException.createCommandNotFoundForArgNum(discriminator, tokens.size() - 1);
   } else if (reducedTable.size() > 1) {
     throw CLIException.createAmbiguousCommandExc(discriminator, tokens.size() - 1);
   } else {
     return reducedTable.get(0);
   }
 }
  public static Object execute(File artemisHome, File artemisInstance, String... args)
      throws Exception {
    try {
      return internalExecute(artemisHome, artemisInstance, args);
    } catch (ConfigurationException configException) {
      System.err.println(configException.getMessage());
      System.out.println();
      System.out.println(
          "Configuration should be specified as 'scheme:location'. Default configuration is 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'");
      return configException;
    } catch (CLIException cliException) {
      System.err.println(cliException.getMessage());
      return cliException;
    } catch (RuntimeException re) {
      System.err.println(re.getMessage());
      System.out.println();

      Cli<Action> parser = builder(null).build();

      parser.parse("help").execute(ActionContext.system());
      return re;
    }
  }