Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Driver

Usage example:

import { Driver   q} from 'cli-driver'
const client = new Driver()
const options = {cwd: '/home/sg/myproject', noSilent: true}
client.start()
client.enter('ls')

// now we wait until package.json is printed in stdout
const data = await client.waitForData(data => data.includes('package.json'))

The options are documented DriverOptions

All methods return promises, so you can use async/await as in the previous example or then().catch().

Emit "data", "exit" and "start" events

Hierarchy

Implements

Index

Properties

andEnter

andEnter: function

An alias for [waitAndEnter].

Type declaration

    • (predicate: string | WriteAndWaitForDataOptions | function, input: string, timeout?: number, interval?: number, afterTimestamp?: number, rejectOnTimeout?: boolean): Promise<string>
    • Parameters

      • predicate: string | WriteAndWaitForDataOptions | function
      • input: string
      • Optional timeout: number
      • Optional interval: number
      • Optional afterTimestamp: number
      • Optional rejectOnTimeout: boolean

      Returns Promise<string>

currentSize

currentSize: object

Type declaration

  • columns: number
  • rows: number

destroyed

destroyed: boolean

forData

forData: waitForData

alias for waitForData

forDataAndEnter

forDataAndEnter: waitForDataAndEnter

forDataAndWrite

forDataAndWrite: waitForDataAndWrite

options

options: DriverOptions

Configuration options of the current instance. Driver is configured on start but options can be changed later while is running.

sleep

sleep: function

Type declaration

    • (ms: number): Promise<this>
    • Parameters

      • ms: number

      Returns Promise<this>

started

started: boolean

time

time: function

Type declaration

    • (ms: number): Promise<this>
    • Parameters

      • ms: number

      Returns Promise<this>

until

until: waitUntil

alias for waitUntil

Static ERROR_ERROR_PUSHED_WAS_NEVER_TRUE

ERROR_ERROR_PUSHED_WAS_NEVER_TRUE: string

Static ERROR_TYPE

ERROR_TYPE: "cli-driver-error"

Static ERROR_WAITUNTIL_INTERVAL_GREATER_THAN_TIMEOUT

ERROR_WAITUNTIL_INTERVAL_GREATER_THAN_TIMEOUT: "ERROR_WAITUNTIL_INTERVAL_GREATER_THAN_TIMEOUT"

this error occurs when unser calls waitUntil* method with an interval greater than timeout

Static ERROR_WAITUNTIL_TIMEOUT

ERROR_WAITUNTIL_TIMEOUT: "ERROR_WAITUNTIL_TIMEOUT"

this error occurs on waitUntil* methods timeouts

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

cleanData

  • cleanData(): this
  • Cleans the data buffer. Useful for making sure that the next data chunk is independent from current state.

    Returns this

destroy

  • destroy(): Promise<this>
  • destroy current terminal

    Returns Promise<this>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

enter

  • enter(input?: string, waitAfterEnter?: number): Promise<void>
  • Will write given text and then press ENTER. Just like write but appending '\r'

    Parameters

    • Optional input: string

      the string to enter

    • Optional waitAfterEnter: number

    Returns Promise<void>

enterAndWait

  • An alias for [enterAndWaitForData] but it will always resolve as string or throw an error otherwise.

    Parameters

    Returns Promise<string>

enterAndWaitForData

  • enterAndWaitForData(input: string | WriteAndWaitForDataOptions, predicate: function | string, timeout?: number, interval?: number, afterTimestamp?: number, rejectOnTimeout?: boolean): Promise<string | false | DriverError>

eventNames

getAllData

  • getAllData(): Promise<string>
  • get all the data collected from start

    Returns Promise<string>

getCommandHistory

  • getCommandHistory(): Promise<Array<any>>
  • get information about all commands run in this driver instance. Will only work when options.debug===true

    Returns Promise<Array<any>>

getCurrentSize

  • getCurrentSize(): object
  • Returns object

    • columns: number
    • rows: number

getDataFromLastWrite

  • getDataFromLastWrite(lastWrite?: number): string
  • Get data from last time write was issued. Remember that other methods like enter could also end up calling write

    Parameters

    • Optional lastWrite: number

      Optional get data from given time

    Returns string

getDataFromTimestamp

  • getDataFromTimestamp(timestamp: number): string
  • Get data printed after given timestamp

    Parameters

    • timestamp: number

    Returns string

getDebugInformation

  • return information about all the commands and state of this driver instance. commandHistory only available when options.debug===true

    Returns Promise<DebugInfo>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getStrippedDataFromLastWrite

  • getStrippedDataFromLastWrite(lastWrite?: number): string

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

resize

  • resize(columns: number, rows: number): Promise<this>
  • Resizes the dimensions of the pty.

    Parameters

    • columns: number

      THe number of columns to use.

    • rows: number

      The number of rows to use.

    Returns Promise<this>

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

start

  • Starts the client with given options. Will spawn a new terminal

    Parameters

    Returns Promise<this>

strip

  • strip(s: string): string

wait

  • wait(...args: Parameters<waitForData>): Promise<string>
  • An alias for [waitForData] but it will always resolve as string or throw an error otherwise.

    Parameters

    Returns Promise<string>

waitAndEnter

  • An alias for [waitForDataAndEnter] but it will always resolve as string or throw an error otherwise.

    Parameters

    Returns Promise<string>

waitForData

  • waitForData(predicate?: function | string | WaitForDataOptions, timeout?: number, interval?: number, afterTimestamp?: number, rejectOnTimeout?: boolean): Promise<string | false | DriverError>
  • Wait until new data matches given predicate. If not predicate is given will return the next data chunk that comes. Based on waitUntil

    Parameters

    • Optional predicate: function | string | WaitForDataOptions

      condition stdout must comply with in other to stop waiting for. If none it will wait until next data chunk is received. If function that's the predicate function the data must comply with. If string, the predicate will be that new data contains this string

    • Optional timeout: number

      wait timeout in ms

    • Optional interval: number

      wait interval in ms

    • Optional afterTimestamp: number

      if provided it will ork with data after that given timestamp. By default this timestamp is the last write()'s

    • Optional rejectOnTimeout: boolean

      By default waitUntil (and all wait* methods) will reject the promise on timeout. Set this to false so they resolve the promise with false value instead

    Returns Promise<string | false | DriverError>

    resolved with the matched data or rejected if no data comply with predicate before timeout

waitForDataAndEnter

  • waitForDataAndEnter(predicate: function | string | WriteAndWaitForDataOptions, input: string, timeout?: number, interval?: number, afterTimestamp?: number, rejectOnTimeout?: boolean): Promise<string | false | DriverError>

waitForDataAndWrite

  • waitForDataAndWrite(predicate: function | string | WriteAndWaitForDataOptions, input: string, timeout?: number, interval?: number, afterTimestamp?: number, rejectOnTimeout?: boolean): Promise<string | false | DriverError>

waitTime

  • waitTime(ms: number): Promise<this>
  • Return a promise resolved after given number of milliseconds

    Parameters

    • ms: number

      will resolve the promise only when given number of milliseconds passed

    Returns Promise<this>

waitUntil

  • waitUntil<T>(predicate: function | WaitUntilOptions<T> | T, timeout?: number, interval?: number, rejectOnTimeout?: boolean): Promise<T | false | DriverError>
  • the more generic wait* method on which all the others are based. Returns a promise that is resolved only when given predicate is fulfilled or rejected if timeout ms passes. THe implementation will be calling the predicate function like polling each interval [[waitInterval]] milliseconds.

    Type parameters

    • T

    Parameters

    • predicate: function | WaitUntilOptions<T> | T

      a function that if return a truthy value will stop the polling

    • Optional timeout: number

      default value is [[waitTimeout]]

    • Optional interval: number

      default value is [[waitInterval]]

    • Optional rejectOnTimeout: boolean

      By default waitUntil (and all wait* methods) will reject the promise on timeout. Set this to false so they resolve the promise with false value instead

    Returns Promise<T | false | DriverError>

    A promise resolved with the return value of the predicate if it ever return truthy or in other case if the predicate never returns truthy in given timeout it will be rejected unless rejectOnTimeout===false in which case the promise is resolved with false

write

  • write(input?: string, waitAfterWrite?: number): Promise<void>
  • Writes given text in the terminal

    Parameters

    • Optional input: string
    • Optional waitAfterWrite: number

      number of milliseconds after which resolve write / enter promise. Default: 0

    Returns Promise<void>

writeAndWaitForData

  • writeAndWaitForData(input: string | WriteAndWaitForDataOptions, predicate: function | string, timeout?: number, interval?: number, afterTimestamp?: number, rejectOnTimeout?: boolean): Promise<string | false | DriverError>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static printWaitUntilPredicate

  • printWaitUntilPredicate(predicate: string | object & function | WaitForDataOptions | any): string
  • Tries to represent a predicate as a string. It accept functions, strings and [WaitForDataOptions]

    Parameters

    Returns string

Static systemIsWindows

  • systemIsWindows(): boolean

Generated using TypeDoc