Пример #1
0
  public static void run(
      BRJS brjs, CommandList commandList, LogLevelAccessor logLevelAccessor, String args[])
      throws CommandOperationException {
    ConsoleWriter out = brjs.getConsoleWriter();

    if (!CommandRunner.extractCommandFromArgs(args).equals(new VersionCommand().getCommandName())) {
      out.println(brjs.versionInfo().toString());
      out.println("");
    }

    doRunCommand(brjs, args, out);
  }
Пример #2
0
  private static void doRunCommand(BRJS brjs, String[] args, ConsoleWriter out)
      throws CommandOperationException {
    try {
      brjs.runCommand(args);
    } catch (NoSuchCommandException e) {
      if (e.getCommandName().length() > 0) {
        out.println(e.getMessage());
        out.println("--------");
        out.println("");
      }
      doRunCommand(brjs, new String[] {new HelpCommand().getCommandName()}, out);
    } catch (CommandArgumentsException e) {
      out.println("Problem:");
      out.println("  " + e.getMessage());
      out.println("");
      out.println("Usage:");
      out.println(
          "  brjs " + e.getCommand().getCommandName() + " " + e.getCommand().getCommandUsage());
    } catch (CommandOperationException e) {
      out.println("Error:");
      out.println("  " + e.getMessage());

      if (e.getCause() != null) {
        out.println("");
        out.println("Caused By:");
        out.println("  " + e.getCause().getMessage());
      }

      out.println("");
      out.println("Stack Trace:");
      StringWriter stackTrace = new StringWriter();
      e.printStackTrace(new PrintWriter(stackTrace));
      out.println(stackTrace.toString());

      throw e;
    }
  }