Options
All
  • Public
  • Public/Protected
  • All
Menu

Utilities for interacting with terminal I/O.

Hierarchy

  • UX

Index

Constructors

constructor

  • new UX(logger: Logger, isOutputEnabled?: boolean, ux?: undefined | object): UX
  • Do not directly construct instances of this class -- use UX.create instead.

    Parameters

    • logger: Logger
    • Default value isOutputEnabled: boolean = true
    • Optional ux: undefined | object

    Returns UX

Properties

cli

cli: object

Type declaration

Static warnings

warnings: Set<string> = new Set<string>()

Collection of warnings that can be accessed and manipulated later.

type

{Set}

Methods

confirm

  • confirm(message: string): Promise<boolean>
  • Prompt the user for confirmation.

    Parameters

    • message: string

      The message displayed to the user.

    Returns Promise<boolean>

    Returns true if the user inputs 'y' or 'yes', and false if the user inputs 'n' or 'no'.

error

  • error(...args: Array<unknown>): UX
  • Logs an error at ERROR level and conditionally writes to stderr if stream output is enabled.

    Parameters

    • Rest ...args: Array<unknown>

      The errors to log.

    Returns UX

errorJson

  • errorJson(obj: object): UX
  • Logs an object as JSON at ERROR level and to stderr.

    throws

    {TypeError} If the object is not JSON-serializable.

    Parameters

    • obj: object

      The error object to log -- must be serializable as JSON.

    Returns UX

getSpinnerStatus

  • getSpinnerStatus(): Optional<string>
  • Get the spinner status.

    Returns Optional<string>

log

  • log(...args: string[]): UX
  • Logs at INFO level and conditionally writes to stdout if stream output is enabled.

    Parameters

    • Rest ...args: string[]

      The messages or objects to log.

    Returns UX

logJson

  • logJson(obj: object): UX
  • Log JSON to stdout and to the log file with log level info.

    throws

    {TypeError} If the object is not JSON-serializable.

    Parameters

    • obj: object

      The object to log -- must be serializable as JSON.

    Returns UX

pauseSpinner

  • pauseSpinner<T>(fn: function, icon?: undefined | string): Optional<T>
  • Pause the spinner and call the given function.

    Type parameters

    • T

    Parameters

    • fn: function

      The function to be called in the pause.

        • (): T
        • Returns T

    • Optional icon: undefined | string

      The string displayed to the user.

    Returns Optional<T>

    The result returned by the passed in function.

prompt

  • prompt(name: string, options?: IPromptOptions): Promise<string>
  • Prompt the user for input.

    Parameters

    • name: string

      The string that the user sees when prompted for information.

    • Default value options: IPromptOptions = {}

      A prompt option configuration.

    Returns Promise<string>

    The user input to the prompt.

setSpinnerStatus

  • setSpinnerStatus(status?: undefined | string): void
  • Update the spinner status.

    Parameters

    • Optional status: undefined | string

      The message displayed to the user.

    Returns void

startSpinner

  • startSpinner(message: string): void
  • Start a spinner action after displaying the given message.

    Parameters

    • message: string

      The message displayed to the user.

    Returns void

stopSpinner

  • stopSpinner(message?: undefined | string): void
  • Stop the spinner action.

    Parameters

    • Optional message: undefined | string

      The message displayed to the user.

    Returns void

styledHeader

  • styledHeader(header: string): UX
  • Logs at INFO level and conditionally writes to stdout in a styled header format if stream output is enabled.

    Parameters

    • header: string

      The header to be styled.

    Returns UX

styledJSON

  • styledJSON(obj: object): UX
  • Log at INFO level and conditionally write to stdout in styled JSON format if stream output is enabled.

    Parameters

    • obj: object

      The object to be styled for stdout.

    Returns UX

styledObject

  • styledObject(obj: object, keys?: string[]): UX
  • Logs at INFO level and conditionally writes to stdout in a styled object format if stream output is enabled.

    Parameters

    • obj: object

      The object to be styled for stdout.

    • Optional keys: string[]

    Returns UX

table

  • Logs at INFO level and conditionally writes to stdout in a table format if stream output is enabled.

    Parameters

    • rows: any[]

      The rows of data to be output in table format.

    • Default value options: TableOptions = {}

      The {@link SfdxTableOptions} to use for formatting.

    Returns UX

warn

  • warn(message: string): UX
  • Logs a warning as WARN level and conditionally writes to stderr if the log level is WARN or above and stream output is enabled. The message is added to the static UX.warnings set if stream output is not enabled, for later consumption and manipulation.

    see

    UX.warnings

    Parameters

    • message: string

      The warning message to output.

    Returns UX

Static create

  • create(): Promise<UX>
  • Create a UX instance.

    Returns Promise<UX>

    A Promise of the created UX instance.

Static formatDeprecationWarning

  • Formats a deprecation warning for display to stderr, stdout, and/or logs.

    Parameters

    Returns string

    The formatted deprecation message.