Beispiel #1
0
 @Test
 public void testParse() throws Exception {
   TestShell shell = new TestShell();
   shell.addAlias("command", "org.jnode.test.shell.syntax.CommandLineTest$TestCommand");
   shell.addSyntax("command", new ArgumentSyntax("arg1"));
   CommandLine cl = new CommandLine(new Token("command"), new Token[] {new Token("fish")}, null);
   CommandInfo cmdInfo = cl.parseCommandLine(shell);
   Command cmd = cmdInfo.createCommandInstance();
   Assert.assertEquals("fish", cmd.getArgumentBundle().getArgument("arg1").getValue());
 }
Beispiel #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;
   }
 }