Class ExpectShell.ExpectShellBuilder

java.lang.Object
com.sshtools.client.shell.ExpectShell.ExpectShellBuilder
Enclosing class:
ExpectShell

public static final class ExpectShell.ExpectShellBuilder extends Object
Builder that creates an ExpectShell.
  • Constructor Details

    • ExpectShellBuilder

      public ExpectShellBuilder()
  • Method Details

    • create

      public static ExpectShell.ExpectShellBuilder create()
      Create a new builder.
      Returns:
      builder
    • withoutDetectSettings

      public ExpectShell.ExpectShellBuilder withoutDetectSettings()
      Prevent operating system and it's settings being detected by examining the stream.
      Returns:
      builder for chaining
    • withDetectSettings

      public ExpectShell.ExpectShellBuilder withDetectSettings(boolean detectSettings)
      Set whether the operating system and it's settings should be detected by examining the stream.
      Parameters:
      detectSettings - detect settings
      Returns:
      builder for chaining
    • withTrigger

      Set a callback that is invoked to query if a command line would allow a shell to start.
      Parameters:
      trigger - shell startup trigger
      Returns:
      builder for chaining
    • withPasswordErrorText

      public ExpectShell.ExpectShellBuilder withPasswordErrorText(String passwordErrorText)
      Set the pattern to look for to indicate failure of a password when prompted. Defaults to ExpectShell.PASSWORD_ERROR_TEXT. This may be a regular expression.
      Parameters:
      passwordErrorText - password error text
      Returns:
      builder for chaining
    • withPasswordPrompt

      public ExpectShell.ExpectShellBuilder withPasswordPrompt(String passwordPrompt)
      Set the pattern to look for for elevated commands using ExpectShell.su(String) and friends that require a password. Defaults to ExpectShell.DEFAULT_PASSWORD_PROMPT. This may be a regular expression.
      Parameters:
      password - prompt
      Returns:
      builder for chaining
    • withEncoding

      public ExpectShell.ExpectShellBuilder withEncoding(String encoding)
      Set the character encoding to use for transferring string content.
      Parameters:
      encoding - encoding
      Returns:
      builder for chaining
    • withEncoding

      public ExpectShell.ExpectShellBuilder withEncoding(Charset encoding)
      Set the character encoding to use for transferring string content.
      Parameters:
      encoding - encoding
      Returns:
      builder for chaining
    • withInput

      public ExpectShell.ExpectShellBuilder withInput(InputStream input)
      Select the InputStream to read input from. You would either manually set the InputStream and OutputStream, or alternatively provide a SessionChannelNG from which to derive the streams.
    • withOutput

      public ExpectShell.ExpectShellBuilder withOutput(OutputStream output)
      Select the OutputStream to write output to. You would either manually set the InputStream and OutputStream, or alternatively provide a SessionChannelNG from which to derive the streams.
    • withSession

      public ExpectShell.ExpectShellBuilder withSession(SessionChannelNG session)
      Specify the session to use, from which the InputStream and OutputStream can be derived. You may alternatively specify the streams yourself.

      Providing the session will also allow the remote server identification to be automatically queries.

      Parameters:
      session - session
      Returns:
      this for chaining
    • withTask

      Specify the task from which to derive the session to use, from which the InputStream and OutputStream can be derived. You may alternatively specify the streams yourself.
      Parameters:
      task - task
      Returns:
      this for chaining
    • withSession

      Specify the remote server identification, which may be used as part of operating system detection. When not provided, and either a SessionChannelNG or a AbstractSessionTask has been provided, the remote identification can be obtain automatically.
      Parameters:
      remoteIdentification - remote identification
      Returns:
      this for chaining
    • withOS

      Specify the operating system for this shell. This will determine various parameters such as the commands to run, exit code variables, newline sequences and more.

      When not specified, the default will be determined by examining the output and environment.

      Parameters:
      os - operating system
      Returns:
      this for chaining
    • withOS

      @Deprecated(forRemoval=true, since="3.1.3") public ExpectShell.ExpectShellBuilder withOS(int os)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specify the operating system for this shell. This will determine various parameters such as the commands to run, exit code variables, newline sequences and more.

      When not specified, the default will be determined by examining the output and environment.

      Parameters:
      os - operating system legacy code
      Returns:
      this for chaining
    • withStartupTimeout

      public ExpectShell.ExpectShellBuilder withStartupTimeout(Duration startupTimeout)
      How long to wait for the shells first prompt before giving up and failing.
      Parameters:
      startupTimeout - startup timeout
      Returns:
      this for chaining
    • withStartupTimeoutSec

      public ExpectShell.ExpectShellBuilder withStartupTimeoutSec(int startupTimeout)
      How long to wait in seconds for the shells first prompt before giving up and failing.
      Parameters:
      startupTimeout - startup timeout in seconds
      Returns:
      this for chaining
    • build

      Build the shell.
      Returns:
      shell
      Throws:
      SshException - on SSH error
      IOException - on IO error
      ShellTimeoutException - on timeout