@Override
protected <T extends CommandLineResult<?>> T sendCommandImpl(
final AbstractConsoleCommand<T> command) {
final ConsoleCallback userCallback = command.getCallback();
Preconditions.checkArgument(command instanceof CommandLine<?, ?>);
checkConnection();
final int[] exitStatus = {0};
final TaskResult<?>[] result = {new TaskResult(Result.ERROR)};
//1. it's also blocking
//2. add callback
final GenericUnixRemoteEnvironmentPlugin.SshSession.WithLowLevelSession withSession = new GenericUnixRemoteEnvironmentPlugin.SshSession.WithLowLevelSession(getBear()) {
@Override
public void act(final Session session, final Session.Shell shell) throws Exception {
final Session.Command execSshCommand = session.exec(command.asText());
final GenericUnixRemoteEnvironmentPlugin.RemoteConsole remoteConsole = (GenericUnixRemoteEnvironmentPlugin.RemoteConsole) new GenericUnixRemoteEnvironmentPlugin.RemoteConsole(session, execSshCommand, new AbstractConsole.Listener() {
@Nonnull
@Override
public ConsoleCallbackResult textAdded(String textAdded, MarkedBuffer buffer) throws Exception {
$.logOutput(textAdded);
if(printToConsole){
System.out.print(textAdded);
}else{
if(!StringUtils.isBlank(textAdded)){
logger.debug("text: {}", textAdded);
}
}
if (Strings.isNullOrEmpty(textAdded)) {
return ConsoleCallbackResult.CONTINUE;
}
final String text = buffer.wholeText();
command.append(text);
if (userCallback != null) {
try {
ConsoleCallbackResult progress = userCallback.progress(console, textAdded, buffer.wholeText());
switch (progress.type) {
case CONTINUE:
break;
case DONE:
return progress;