private InvocationMatch<T> match(final Iterable<Token> tokens) throws SyntaxException { Tokenizer tokenizer = new Tokenizer() { /** . */ Iterator<Token> i = tokens.iterator(); @Override protected Token parse() { return i.hasNext() ? i.next() : null; } }; return match(tokenizer); }
public InvocationMatch<T> parse(String s) throws SyntaxException { ArrayList<Token> tokens = new ArrayList<Token>(); for (Token token : this.tokens) { tokens.add(token); } for (Iterator<Token> i = new TokenizerImpl(s);i.hasNext();) { tokens.add(i.next()); } return match(tokens); }
public InvocationMatch<T> arguments(List<?> arguments) throws SyntaxException { TokenList tokens = new TokenList(this.tokens); for (Object argument : arguments) { tokens.add(new Token.Literal.Word(tokens.last(), argument.toString())); } return match(tokens); }
private InvocationMatch<T> match(final Iterable<Token> tokens) throws SyntaxException { Tokenizer tokenizer = new Tokenizer() { /** . */ Iterator<Token> i = tokens.iterator(); @Override protected Token parse() { return i.hasNext() ? i.next() : null; } }; return match(tokenizer); }
public InvocationMatch<T> parse(String s) throws SyntaxException { ArrayList<Token> tokens = new ArrayList<Token>(); for (Token token : this.tokens) { tokens.add(token); } for (Iterator<Token> i = new TokenizerImpl(s);i.hasNext();) { tokens.add(i.next()); } return match(tokens); }
public InvocationMatch<T> match(String s) throws SyntaxException { return match(new TokenizerImpl(s)); }
private static <T> void handle(Class<T> commandClass, String line) throws Exception { CommandDescriptorImpl<T> descriptor = CommandFactory.DEFAULT.create(commandClass); descriptor = HelpDescriptor.create(descriptor); InvocationMatcher<T> matcher = descriptor.invoker("main"); InvocationMatch<T> match = matcher.match(line); T instance = commandClass.newInstance(); Object o = match.invoke(instance); if (o != null) { System.out.println(o); } } }
public CommandInvoker<?, ?> resolveInvoker(String name, Map<String, ?> options, List<?> args) { if (options.containsKey("h") || options.containsKey("help")) { throw new UnsupportedOperationException("Implement me"); } else { InvocationMatcher matcher = descriptor.invoker("main"); InvocationMatch<CRaSHCommand> match = null; try { match = matcher.match(name, options, args); } catch (org.crsh.cli.SyntaxException e) { throw new org.crsh.command.SyntaxException(e.getMessage()); } return resolveInvoker(match); } }
@Override public void run() { try { CommandDescriptorImpl<Agent> c = CommandFactory.DEFAULT.create(Agent.class); InvocationMatcher<Agent> matcher = c.invoker("main"); InvocationMatch<Agent> match = matcher.match(agentArgs); match.invoke(new Agent(inst)); } catch (Exception e) { e.printStackTrace(); } } };
public InvocationMatch<T> arguments(List<?> arguments) throws SyntaxException { TokenList tokens = new TokenList(this.tokens); for (Object argument : arguments) { tokens.add(new Token.Literal.Word(tokens.last(), argument.toString())); } return match(tokens); }
public static void main(String[] args) throws Exception { StringBuilder line = new StringBuilder(); for (int i = 0;i < args.length;i++) { if (i > 0) { line.append(' '); } Delimiter.EMPTY.escape(args[i], line); } // CRaSH main = new CRaSH(); InvocationMatcher<CRaSH> matcher = main.descriptor.invoker("main"); InvocationMatch<CRaSH> match = matcher.match(line.toString()); match.invoke(new CRaSH()); } }
public CommandInvoker<?, ?> resolveInvoker(String line) { InvocationMatcher analyzer = descriptor.invoker("main"); InvocationMatch<CRaSHCommand> match; try { match = analyzer.match(line); } catch (org.crsh.cli.SyntaxException e) { throw new org.crsh.command.SyntaxException(e.getMessage()); } return resolveInvoker(match); }
match = analyzer.match(line);
@Override public Command createCommand(String command) { // if (command.startsWith("scp ")) { try { command = command.substring(4); SCPAction action = new SCPAction(); CommandDescriptorImpl<SCPAction> descriptor = CommandFactory.DEFAULT.create(SCPAction.class); InvocationMatcher<SCPAction> analyzer = descriptor.invoker("main"); InvocationMatch<SCPAction> match = analyzer.match(command); match.invoke(Resolver.EMPTY, action); if (Boolean.TRUE.equals(action.isSource())) { return new SourceCommand(action.getTarget(), Boolean.TRUE.equals(action.isRecursive())); } else if (Boolean.TRUE.equals(action.isSink())) { return new SinkCommand(action.getTarget(), Boolean.TRUE.equals(action.isRecursive())); } else { return new FailCommand("Cannot execute command " + command); } } catch (CLIException e) { return new FailCommand("Cannot execute command " + command, e); } } else { return new FailCommand("Cannot execute command " + command); } } }
return match(tokenizer);