public int runCommand(final String command) {
    int errorCode = NO_ERROR;

    RemoteServerSpecificCommand.validateClient(terminal.writer(), restClient);
    try {
      // Commands executed by the '-e' parameter do not need to execute specific CLI
      // commands. For RUN SCRIPT commands, users can use the '-f' command parameter.
      handleLine(command);
    } catch (final EndOfFileException exception) {
      // Ignore - only used by runInteractively() to exit the CLI
    } catch (final Exception exception) {
      errorCode = ERROR;
      LOGGER.error("An error occurred while running a command. Error = "
          + exception.getMessage(), exception);

      terminal.printError(ErrorMessageUtil.buildErrorMessage(exception),
          exception.toString());
    }

    terminal.flush();

    return errorCode;
  }
@Test
  public void shouldPrintErrorIfCantConnectToRestServerOnRunCommand() throws Exception {
    givenRunInteractivelyWillExit();

    final KsqlRestClient mockRestClient = givenMockRestClient();
    when(mockRestClient.getServerInfo())
        .thenThrow(new KsqlRestClientException("Boom", new IOException("")));

    final int error_code = new Cli(1L, 1L, mockRestClient, console)
        .runCommand("this is a command");

    assertThat(error_code, is(-1));
    assertThat(terminal.getOutputString(),
        containsString("Please ensure that the URL provided is for an active KSQL server."));
  }