@Override public GfshParseResult parse(String userInput) { String rawInput = convertToSimpleParserInput(userInput); // this tells the simpleParser not to interpret backslash as escaping character rawInput = rawInput.replace("\\", "\\\\"); // User SimpleParser to parse the input ParseResult result = super.parse(rawInput); if (result == null) { return null; } return new GfshParseResult(result.getMethod(), result.getInstance(), result.getArguments(), userInput); }
private Object invoke(ParseResult parseResult) { try { Method method = parseResult.getMethod(); ReflectionUtils.makeAccessible(method); return ReflectionUtils.invokeMethod(method, parseResult.getInstance(), parseResult.getArguments()); } catch (Throwable th) { logger.severe("Command failed " + th); return handleThrowable(th); } }
/** * This Code piece allows lens cli to be able to parse list arguments. It can already parse keyword args. * More details at https://github.com/spring-projects/spring-shell/issues/72 * @param parseResult * @return */ @Override public ParseResult beforeInvocation(ParseResult parseResult) { Object[] args = parseResult.getArguments(); if (args != null && Sets.newHashSet(args).size() == 1) { if (args[0] instanceof String) { String[] split = ((String) args[0]).split("\\s+"); Object[] newArgs = new String[args.length]; System.arraycopy(split, 0, newArgs, 0, split.length); parseResult = new ParseResult(parseResult.getMethod(), parseResult.getInstance(), newArgs); } } return parseResult; }
/** * This Code piece allows lens cli to be able to parse list arguments. It can already parse keyword args. * More details at https://github.com/spring-projects/spring-shell/issues/72 * @param parseResult * @return */ @Override public ParseResult beforeInvocation(ParseResult parseResult) { Object[] args = parseResult.getArguments(); if (args != null && Sets.newHashSet(args).size() == 1) { if (args[0] instanceof String) { String[] split = ((String) args[0]).split("\\s+"); Object[] newArgs = new String[args.length]; System.arraycopy(split, 0, newArgs, 0, split.length); parseResult = new ParseResult(parseResult.getMethod(), parseResult.getInstance(), newArgs); } } return parseResult; }
public Object execute(ParseResult parseResult) throws RuntimeException { Object obj = null; String command = null; try { String method = parseResult.getMethod().getName(); String className = parseResult.getInstance().getClass().getCanonicalName(); command = className + "." + method; Util.log("Executing command " + command + " with Gfsh instance " + gfshThreadLocal.get()); long l1 = System.currentTimeMillis(); obj = oldStrategy.execute(parseResult); long l2 = System.currentTimeMillis(); Util.log("Completed execution of command " + command + " in " + (l2-l1) + " ms."); if(obj!=null){ Util.log("Command output class is " + obj.getClass()); }else{ obj = "VOID"; } } catch (Exception e) { addError("Error running command " , e); throw new RuntimeException(e); } Util.debug("Adding outuut and notifying threads .."); addOutput(command, obj); if(command.equals(EXIT_SHELL_COMMAND)) resultLatch.countDown(); return obj; }
public Object execute(ParseResult parseResult) throws RuntimeException { Assert.notNull(parseResult, "Parse result required"); synchronized (mutex) { Assert.isTrue(isReadyForCommands(), "SimpleExecutionStrategy not yet ready for commands"); Object target = parseResult.getInstance(); if (target instanceof ExecutionProcessor) { ExecutionProcessor processor = ((ExecutionProcessor) target); parseResult = processor.beforeInvocation(parseResult); try { Object result = invoke(parseResult); processor.afterReturningInvocation(parseResult, result); return result; } catch (Throwable th) { processor.afterThrowingInvocation(parseResult, th); return handleThrowable(th); } } else { return invoke(parseResult); } } }
public static Object execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) { CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); if (steps != null) {
result = ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());
public static Object execCLISteps(LogWrapper logWrapper, Gfsh shell, ParseResult parseResult) { CLIStep[] steps = (CLIStep[]) ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments()); if (steps != null) {
result = ReflectionUtils.invokeMethod(parseResult.getMethod(), parseResult.getInstance(), parseResult.getArguments());