Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cli-ux

oclif3.1mMITdeprecated6.0.9TypeScript support: included

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

cli IO utilities

oclif

readme

cli-ux

========= This module has been deprecated in favor of oclif/core and will no longer be maintained. =========

cli IO utilities

Version CircleCI Appveyor CI Known Vulnerabilities Downloads/week License

Usage

The following assumes you have installed cli-ux to your project with npm install cli-ux or yarn add cli-ux and have it required in your script (TypeScript example):

import cli from 'cli-ux'
cli.prompt('What is your name?')

JavaScript:

const {cli} = require('cli-ux')

cli.prompt('What is your name?')

cli.prompt()

Prompt for user input.

// just prompt for input
await cli.prompt('What is your name?')

// mask input after enter is pressed
await cli.prompt('What is your two-factor token?', {type: 'mask'})

// mask input on keypress (before enter is pressed)
await cli.prompt('What is your password?', {type: 'hide'})

// yes/no confirmation
await cli.confirm('Continue?')

// "press any key to continue"
await cli.anykey()

prompt demo

cli.url(text, uri)

Create a hyperlink (if supported in the terminal)

await cli.url('sometext', 'https://google.com')
// shows sometext as a hyperlink in supported terminals
// shows https://google.com in unsupported terminals

url demo

cli.open

Open a url in the browser

await cli.open('https://oclif.io')

cli.action

Shows a spinner

// start the spinner
cli.action.start('starting a process')
// show on stdout instead of stderr
cli.action.start('starting a process', 'initializing', {stdout: true})

// stop the spinner
cli.action.stop() // shows 'starting a process... done'
cli.action.stop('custom message') // shows 'starting a process... custom message'

This degrades gracefully when not connected to a TTY. It queues up any writes to stdout/stderr so they are displayed above the spinner.

action demo

cli.annotation

Shows an iterm annotation

cli.annotation('sometext', 'annotated with this text')

annotation demo

cli.wait

Waits for 1 second or given milliseconds

await cli.wait()
await cli.wait(3000)

cli.table

Displays tabular data

cli.table(data, columns, options)

Where:

cli.table.flags() returns an object containing all the table flags to include in your command.

{
  columns: Flags.string({exclusive: ['additional'], description: 'only show provided columns (comma-separated)'}),
  sort: Flags.string({description: 'property to sort by (prepend '-' for descending)'}),
  filter: Flags.string({description: 'filter property by partial string matching, ex: name=foo'}),
  csv: Flags.boolean({exclusive: ['no-truncate'], description: 'output is csv format'}),
  extended: Flags.boolean({char: 'x', description: 'show extra columns'}),
  'no-truncate': Flags.boolean({exclusive: ['csv'], description: 'do not truncate output to fit screen'}),
  'no-header': Flags.boolean({exclusive: ['csv'], description: 'hide table header from output'}),
}

Passing {only: ['columns']} or {except: ['columns']} as an argument into cli.table.flags() will allow/block those flags from the returned object.

Table.Columns defines the table columns and their display options.

const columns: Table.Columns = {
  // where `.name` is a property of a data object
  name: {}, // "Name" inferred as the column header
  id: {
    header: 'ID', // override column header
    minWidth: '10', // column must display at this width or greater
    extended: true, // only display this column when the --extended flag is present
    get: row => `US-O1-${row.id}`, // custom getter for data row object
  },
}

Table.Options defines the table options, most of which are the parsed flags from the user for display customization, all of which are optional.

const options: Table.Options = {
  printLine: myLogger, // custom logger
  columns: flags.columns,
  sort: flags.sort,
  filter: flags.filter,
  csv: flags.csv,
  extended: flags.extended,
  'no-truncate': flags['no-truncate'],
  'no-header': flags['no-header'],
}

Example class:

import {Command} from '@oclif/core'
import {cli} from 'cli-ux'
import axios from 'axios'

export default class Users extends Command {
  static flags = {
    ...cli.table.flags()
  }

  async run() {
    const {flags} = this.parse(Users)
    const {data: users} = await axios.get('https://jsonplaceholder.typicode.com/users')

    cli.table(users, {
      name: {
        minWidth: 7,
      },
      company: {
        get: row => row.company && row.company.name
      },
      id: {
        header: 'ID',
        extended: true
      }
    }, {
      printLine: this.log,
      ...flags, // parsed flags
    })
  }
}

Displays:

$ example-cli users
Name                     Company
Leanne Graham            Romaguera-Crona
Ervin Howell             Deckow-Crist
Clementine Bauch         Romaguera-Jacobson
Patricia Lebsack         Robel-Corkery
Chelsey Dietrich         Keebler LLC
Mrs. Dennis Schulist     Considine-Lockman
Kurtis Weissnat          Johns Group
Nicholas Runolfsdottir V Abernathy Group
Glenna Reichert          Yost and Sons
Clementina DuBuque       Hoeger LLC

$ example-cli users --extended
Name                     Company            ID
Leanne Graham            Romaguera-Crona    1
Ervin Howell             Deckow-Crist       2
Clementine Bauch         Romaguera-Jacobson 3
Patricia Lebsack         Robel-Corkery      4
Chelsey Dietrich         Keebler LLC        5
Mrs. Dennis Schulist     Considine-Lockman  6
Kurtis Weissnat          Johns Group        7
Nicholas Runolfsdottir V Abernathy Group    8
Glenna Reichert          Yost and Sons      9
Clementina DuBuque       Hoeger LLC         10

$ example-cli users --columns=name
Name
Leanne Graham
Ervin Howell
Clementine Bauch
Patricia Lebsack
Chelsey Dietrich
Mrs. Dennis Schulist
Kurtis Weissnat
Nicholas Runolfsdottir V
Glenna Reichert
Clementina DuBuque

$ example-cli users --filter="company=Group"
Name                     Company
Kurtis Weissnat          Johns Group
Nicholas Runolfsdottir V Abernathy Group

$ example-cli users --sort=company
Name                     Company
Nicholas Runolfsdottir V Abernathy Group
Mrs. Dennis Schulist     Considine-Lockman
Ervin Howell             Deckow-Crist
Clementina DuBuque       Hoeger LLC
Kurtis Weissnat          Johns Group
Chelsey Dietrich         Keebler LLC
Patricia Lebsack         Robel-Corkery
Leanne Graham            Romaguera-Crona
Clementine Bauch         Romaguera-Jacobson
Glenna Reichert          Yost and Sons

cli.tree

Generate a tree and display it

let tree = cli.tree()
tree.insert('foo')
tree.insert('bar')

let subtree = cli.tree()
subtree.insert('qux')
tree.nodes.bar.insert('baz', subtree)

tree.display()

Outputs:

├─ foo
└─ bar
   └─ baz
      └─ qux

cli.progress

Generate a customizable progress bar and display it

const simpleBar = cli.progress()
simpleBar.start()

const customBar = cli.progress({
                   format: 'PROGRESS | {bar} | {value}/{total} Files',
                   barCompleteChar: '\u2588',
                   barIncompleteChar: '\u2591',
                 })
customBar.start()

Outputs:

bar1:
progress [=====================-------------------] 53% | ETA: 1s | 53/100
bar2:
PROGRESS | █████████████████████████████░░░░░░░░░░░ | 146/204 Files

To see a more detailed example, run shell script $ ts-node examples/progress.ts

This extends cli-progress see all of the options and customizations there, which can be passed in with the options object. Only the single bar variant of cli-progress is currently supported.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

6.0.9 (2022-01-31)

Bug Fixes

6.0.8 (2022-01-10)

Bug Fixes

  • security: bump cli-progress (0511944)

6.0.7 (2022-01-06)

Bug Fixes

6.0.6 (2021-12-08)

Bug Fixes

6.0.5 (2021-12-07)

Bug Fixes

6.0.4 (2021-12-06)

Bug Fixes

6.0.3 (2021-12-02)

Bug Fixes

  • update oclif/core imports (74fdab5)

6.0.2 (2021-12-01)

Bug Fixes

6.0.1 (2021-12-01)

Bug Fixes

  • bump deps and correct/suppress lint errors (#450) (bc0935c)

6.0.0 (2021-10-04)

⚠ BREAKING CHANGES

  • require node 12+ (#413)

Features

build

5.6.3 (2021-07-07)

Bug Fixes

  • makes the max terminal width for tables correct on Windows machines (#386) (4e5c19b)

5.6.2 (2021-06-21)

5.6.1 (2021-06-11)

5.6.0 (2021-06-09)

Features

  • add title to tables and improve output structure (#364) (46f1c18)

Bug Fixes

  • use npm-release-management-orb for CI (#379) (1d01a18)

5.5.1 (2020-11-12)

Bug Fixes

  • Downgrade fs-extra to support Node.js 8 (#275) (5b92e86)

5.5.0 (2020-08-28)

Features

  • support multiple filter flags for table (#156) (057c852)

Reverts

  • Revert "feat: support multiple filter flags for table (#156)" (#231) (c008a42), closes #156 #231

5.4.10 (2020-08-07)

Bug Fixes

  • do not cache require, require is already cached in NodeJS by design (#194) (99b9466)

5.4.9 (2020-07-02)

Reverts

  • Revert "build: downgrade to semantic-release@15" (dfeab27)

5.4.7 (2020-07-02)

Bug Fixes

Bug Fixes

4.9.2 (2018-10-29)

Bug Fixes

4.9.1 (2018-10-13)

Bug Fixes

4.9.0 (2018-10-10)

Features

4.8.2 (2018-09-13)

Bug Fixes

  • ensure ansi-escapes is added (ed4038f)

4.8.1 (2018-08-28)

Bug Fixes

  • Move [@oclif](https://github.com/oclif)/errors into dependencies (#49) (a9cf484)

4.8.0 (2018-08-17)

Features

4.7.3 (2018-06-22)

Bug Fixes

  • anykey: allow pressing "enter" (b2215eb)

4.7.2 (2018-06-19)

Bug Fixes

  • table: Allow user to override tableoptions (#40) (14b972e), closes #37

4.7.1 (2018-06-15)

Bug Fixes

  • add newline after anykey (13ccb4d)

4.7.0 (2018-06-15)

Features

4.6.3 (2018-06-12)

Bug Fixes

4.6.2 (2018-06-10)

Bug Fixes

4.6.1 (2018-06-01)

Bug Fixes

4.6.0 (2018-06-01)

Features

4.5.1 (2018-05-31)

Bug Fixes

4.5.0 (2018-05-31)

Features

4.4.1 (2018-05-31)

Bug Fixes

4.4.0 (2018-05-23)

Bug Fixes

Features

4.3.1 (2018-05-18)

Bug Fixes

4.3.0 (2018-05-13)

Bug Fixes

Features

4.2.3 (2018-05-12)

Bug Fixes

4.2.2 (2018-05-12)

Bug Fixes

4.2.1 (2018-05-10)

Bug Fixes

  • allow ux.log() with no args (6182edc)

4.2.0 (2018-05-09)

Features

4.1.0 (2018-05-09)

Features

4.0.1 (2018-05-08)

Bug Fixes

4.0.0 (2018-05-06)

Features

BREAKING CHANGES

  • all the error logging functions have been moved to @oclif/errors

3.5.0 (2018-05-06)

Bug Fixes

Features

3.4.1 (2018-04-21)

Bug Fixes

3.4.0 (2018-04-21)

Features

  • allow the user to require no input, which allows for defaults (#27) (93a182d)

3.3.31 (2018-04-18)

Bug Fixes

3.3.30 (2018-04-10)

Bug Fixes

  • updated supportsColor reference (0e5b0e9)

3.3.29 (2018-04-10)

Bug Fixes

  • disable spinner when TERM=emacs-color (6917831)
  • fixed errlog default (7adfa9a)

3.3.28 (2018-04-09)

Bug Fixes

3.3.27 (2018-04-06)

Bug Fixes

  • allow stdout/stderr to work with stdout-stderr for testing (6fea4ad)

3.3.26 (2018-03-23)

Bug Fixes

3.3.25 (2018-03-08)

Bug Fixes

  • default table formatter to display falsy values. (14ea34c)

3.3.24 (2018-02-28)

Bug Fixes

3.3.23 (2018-02-16)

Bug Fixes

  • use stderr for action by default (536a5d7)

3.3.20 (2018-02-14)

Bug Fixes

3.3.19 (2018-02-13)

Bug Fixes

3.3.18 (2018-02-06)

Bug Fixes

3.3.17 (2018-02-05)

Bug Fixes

3.3.16 (2018-02-05)

Bug Fixes

  • allow globals to be set without major version (582601b)

3.3.15 (2018-02-05)

Bug Fixes

3.3.14 (2018-02-04)

Bug Fixes

  • default to display stack trace (20d719c)

3.3.13 (2018-02-02)

Bug Fixes

  • remove extra newline from styledJSON (8ce11fc)

3.3.12 (2018-02-01)

Bug Fixes

3.3.11 (2018-02-01)

Bug Fixes

  • add newline after context (0c89185)

3.3.10 (2018-01-31)

Bug Fixes

3.3.9 (2018-01-31)

Bug Fixes

3.3.8 (2018-01-28)

Bug Fixes

3.3.7 (2018-01-28)

Bug Fixes

3.3.6 (2018-01-28)

Bug Fixes

3.3.5 (2018-01-28)

Bug Fixes

  • add newline before context (5ada0f5)

3.3.4 (2018-01-28)

Bug Fixes

  • strip ansi from context (5523431)

3.3.3 (2018-01-28)

Bug Fixes

  • set content type to object (fcefe79)

3.3.2 (2018-01-28)

Bug Fixes

  • show stack trace in errlog (baa6749)

3.3.1 (2018-01-28)

Bug Fixes

  • default severity to error (1b8881a)

3.3.0 (2018-01-28)

Features

3.2.2 (2018-01-28)

Bug Fixes

  • fixed logging on windows (ed1f207)

3.2.1 (2018-01-27)

Bug Fixes

3.2.0 (2018-01-26)

Bug Fixes

Features

3.1.7 (2018-01-26)

Bug Fixes

3.1.6 (2018-01-26)

Bug Fixes

  • show stack trace when debug is on (2841c67)

3.1.5 (2018-01-21)

Bug Fixes

3.1.4 (2018-01-20)

Bug Fixes

  • only display error when unhandled (5631c04)

3.1.3 (2018-01-20)

Bug Fixes

3.1.2 (2018-01-20)

Bug Fixes

3.1.1 (2018-01-20)

Bug Fixes

3.1.0 (2018-01-19)

Features

  • allow setting scope in warn/error/fatal call (b6e1933)

3.0.1 (2018-01-19)

Bug Fixes

  • add newline after traceback (d97fe55)

3.0.0 (2018-01-19)

Bug Fixes

Features

BREAKING CHANGES

  • removed mocking ability. Use @dxcli/dev-test or std-mocks instead for this functionality.

2.1.0 (2018-01-19)

Bug Fixes

Features