Esempio n. 1
0
  @Override
  public void execute() throws Exception {
    final PrintWriter err = getError().getPrintWriter();
    final File file = argFile.getValue();

    Shell shell = null;
    try {
      shell = ShellUtils.getShellManager().getCurrentShell();
    } catch (NameNotFoundException e) {
      e.printStackTrace(err);
      exit(2);
    }

    if (shell == null) {
      err.println(err_null);
      exit(2);
    }

    String[] args = argArgs.getValues();

    int rc = shell.runCommandFile(file, null, args);
    if (rc != 0) {
      exit(rc);
    }
  }
Esempio n. 2
0
 @Override
 public void execute() throws NameNotFoundException, ShellException, HelpException {
   // The above exceptions are either bugs or configuration errors and should be allowed
   // to propagate so that the shell can diagnose them appropriately.
   String alias;
   CommandLine commandLine = getCommandLine();
   PrintWriter out = getOutput().getPrintWriter();
   PrintWriter err = getError().getPrintWriter();
   if (argAlias.isSet()) {
     alias = argAlias.getValue();
   } else if (commandLine.getCommandName() != null) {
     alias = commandLine.getCommandName();
   } else {
     alias = "help";
   }
   CommandShell shell = null;
   try {
     shell = (CommandShell) ShellUtils.getShellManager().getCurrentShell();
     CommandInfo cmdInfo = shell.getCommandInfo(alias);
     Help cmdHelp = HelpFactory.getHelpFactory().getHelp(alias, cmdInfo);
     if (cmdHelp == null) {
       err.format(err_no_help, alias);
       exit(1);
     }
     cmdHelp.help(out);
     otherAliases(shell.getAliasManager(), alias, cmdInfo.getCommandClass().getName(), out);
   } catch (HelpException ex) {
     err.format(err_help_ex, alias, ex.getLocalizedMessage());
     throw ex;
   } catch (ShellException ex) {
     err.println(ex.getMessage());
     throw ex;
   } catch (SecurityException ex) {
     err.format(err_sec_ex, alias, ex.getLocalizedMessage());
     throw ex;
   }
 }