@cto.ai/sdk
A collection of common interactive command line user interfaces.
Last updated 5 days ago by jplew .
ISC · Original npm · Tarball · package.json
$ cnpm install @cto.ai/sdk 
SYNC missed versions from official npm registry.

Inquirer.js

A collection of common interactive command line user interfaces.

Table of Contents

  1. Documentation
    1. Installation
    2. Methods
      1. Prompt
      2. Colors
      3. Spinners
      4. Wait
      5. Url
      6. Annotation
      7. Table
      8. Tree
      9. ProgressBar
      10. Notify

Documentation

Installation

npm install @cto.ai/sdk
const { sdk, ux, log } from '@cto.ai/sdk';

Methods

ux.prompt

Launch the prompt interface

const answers = await ux.prompt(questions);

Question A question object is a hash containing question related values:

Question

A question object is a hash containing question related values:

  • type: (String) Type of the prompt. Defaults: input - Possible values: input, number, confirm, list, rawlist, expand, checkbox, password, editor, datetime, autocomplete
  • name: (String) The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
  • message: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of name (followed by a colon).
  • default: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
  • choices: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers. Array values can be simple strings, or objects containing a name (to display in list), a value (to save in the answers hash) and a short (to display after selection) properties. The choices array can also contain a Separator.
  • validate: (Function) Receive the user input and answers hash. Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
  • filter: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the Answers hash.
  • transformer: (Function) Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
  • when: (Function, Boolean) Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
  • pageSize: (Number) Change the number of lines that will be rendered when using list, rawList, expand or checkbox.
  • prefix: (String) Change the default prefix message.
  • suffix: (String) Change the default suffix message.
  • afterMessage: (String) replaces message after question is answered.

for more information: https://github.com/SBoudrias/Inquirer.js#documentation

ux.colors

ux.colors.green('Green text');
ux.colors.red('Red text');

for more information: https://github.com/chalk/chalk#usage

ux.spinner

Shows a spinner

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

// stop the spinner
ux.spinner.stop(); // shows 'starting a process... done'
ux.spinner.stop('custom message'); // shows 'starting a process... custom message'

ux.wait

Waits for 1 second or given milliseconds

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

ux.url

Create a hyperlink (if supported in the terminal)

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

ux.annotation

Shows an iterm annotation

cli.annotation('sometest', 'annotated with this text');

ux.table

Displays tabular data

ux.table(data, columns, options);

for more information: https://github.com/oclif/cli-ux#clitable

ux.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

Current Tags

  • 1.3.2                                ...           latest (5 days ago)

16 Versions

  • 1.3.2                                ...           5 days ago
  • 1.3.0                                ...           20 days ago
  • 1.0.13                                ...           a month ago
  • 1.0.12                                ...           a month ago
  • 1.0.11                                ...           a month ago
  • 1.0.10                                ...           a month ago
  • 1.0.9                                ...           a month ago
  • 1.0.8                                ...           a month ago
  • 1.0.7                                ...           2 months ago
  • 1.0.6                                ...           2 months ago
  • 1.0.5                                ...           2 months ago
  • 1.0.4                                ...           2 months ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.1                                ...           2 months ago
  • 1.0.0                                ...           2 months ago
Downloads
Today 0
This Week 0
This Month 47
Last Day 0
Last Week 47
Last Month 166
Dependencies (24)
Dev Dependencies (8)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |