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 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); }
public final String describe(String line, DescriptionFormat mode) { InvocationMatcher analyzer = descriptor.invoker("main");
@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); } } }