VERSION:1.0.2
Published about 1 year ago by @cto.ai
cto.ai/
hello-world

šŸš€ CTO.ai - Official Op - Hello World šŸš€

A Demo of some interactive prompts using the Ops Platform.

This Op was generated with ops init. Have a look at demo.js and the examples below to see how you can leverage the @cto.ai/sdk to build ops.

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

#https://github.com/cto-ai/hello-world/blob/master/#%20[Documentation](#documentation)

Installation

npm install @cto.ai/sdk
const { sdk, ux } 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:

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

Prompt types


https://github.com/cto-ai/hello-world/blob/master/*Note:*:%20_allowed%20options%20written%20inside%20square%20brackets%20(%60[]%60) are optional. Others are required._

List - {type: 'list'}

Take type, name, message, choices[, default, filter] properties. (Note that default must be the choice index in the array or a choice value)

List prompt


Raw List - {type: 'rawlist'}

Take type, name, message, choices[, default, filter] properties. (Note that default must be the choice index in the array)

Raw list prompt


Expand - {type: 'expand'}

Take type, name, message, choices[, default] properties. (Note that default must be the choice index in the array. If default key not provided, then help will be used as default choice)

Note that the choices object will take an extra parameter called key for the expand prompt. This parameter must be a single (lowercased) character. The h option is added by the prompt and shouldn't be defined by the user.

See examples/expand.js for a running example.

Expand prompt closed Expand prompt expanded


Checkbox - {type: 'checkbox'}

Take type, name, message, choices[, filter, validate, default] properties. default is expected to be an Array of the checked choices value.

Choices marked as {checked: true} will be checked by default.

Choices whose property disabled is truthy will be unselectable. If disabled is a string, then the string will be outputted next to the disabled choice, otherwise it'll default to "Disabled". The disabled property can also be a synchronous function receiving the current answers as argument and returning a boolean or a string.

Checkbox prompt


Confirm - {type: 'confirm'}

Take type, name, message, [default] properties. default is expected to be a boolean if used.

Confirm prompt


Input - {type: 'input'}

Take type, name, message[, default, filter, validate, transformer] properties.

Input prompt


Input - {type: 'number'}

Take type, name, message[, default, filter, validate, transformer] properties.


Password - {type: 'password'}

Take type, name, message, mask,[, default, filter, validate] properties.

Password prompt


Note that mask is required to hide the actual user input.

Editor - {type: 'editor'}

Take type, name, message[, default, filter, validate] properties

Launches an instance of the users preferred editor on a temporary file. Once the user exits their editor, the contents of the temporary file are read in as the result. The editor to use is determined by reading the $VISUAL or $EDITOR environment variables. If neither of those are present, notepad (on Windows) or vim (Linux or Mac) is used.

Checkbox with autocomplete - {type: 'checkbox-plus'}

Takes type, name, message, source [, filter, validate, default, pageSize, highlight, searchable, enablebackspace, answer, footer, header, keypress, searching, noresult] properties.

Checkbox1

Checkbox2

for example and more information: https://github.com/yviscool/inquirer-checkbox-plus

Fuzzy path - {type: 'fuzzypath'}

Take type, name, message [, excludePath, itemType, rootPath, suggestOnly]

FuzzyPath1

FuzzyPath2

for example and more information: https://github.com/adelsz/inquirer-fuzzy-path

Emoji - {type: 'emoji'}

Take type, name, message

for example and more information: https://github.com/tannerntannern/inquirer-emoji

Emoji

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

sdk.track

Send a track event to cto.ai api

sdk.track(tags, metadata)