Skip to content

Latest commit

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Installation

npm i quick-cli --save
#or
yarn add quick-cli

Usage

This doc is for version 2.x.x, there are multiple breaking changes since 1.0.x

init

varcli=require('quick-cli'),

out

const{out,dev}=cli;// choose meaning of your out text, quick-cli will apply colorsout.err('terrible error');out.warn('bad warning');out.info('some info');out.log('important log');out.success('success msg');out.form('question');// you can use multiple strings at onceout.log('some','text','split','into','multiple','strings')// to display something only in dev/debug mode, use dev instead of outout.info('lorem ipsum');dev.info('lorem ipsum');// activate/deactivate dev, .dev content is being display only if development mode is oncli.setDevelopmentMode(true);// --OR--cli.setDevelopmentMode(false);// to apply color to string and display it later with another lib use applyColor:cli.applyColor('lorem ipsum','info');constraw_text="lorem ipsum";constcolorful_text=cli.applyColor(raw_text,'info');console.info(colorful_text);// both will displaycli.out(raw_text,'info');// formatted text// you can add own colors with setColorconstchalk=require("chalk");cli.addColor("cyantext",(...text)=>chalk.cyan(...text))out.cyantext("it ","works!")

input

There are to ways to request user input with quick-cli: async and sync

They are avaiable in cli.input and cli.syncInput.

  • Synchronous methods will block your thread until user finishes entering input and return his input.
  • Asynchronous methods will simply return a promise that resolves to user input.

In both cases, avaiable methods are:

  • text(questionText, defaultValue, validator) - user will be presented with questionText and asked to type his anwser.
  • password(questionText, validator) - similar to text but anwser won't be displayed and there can't be a default value.
  • list(questionText, choices) - user will be presented with list of choices and asked to choose only one.
  • checkbox(questionText, choices) - user will be presented with list of choices and asked to choose as many as he wants.
  • confirm(questionText) - user will be presented with questionText and asked to anwser yes/no.

input example

inputSync.text("Enter some random text")awaitinputAsync.text("Enter some random text")inputSync.pass("And some secret password")inputAsync.pass("And some secret password")inputSync.confirm("Do you agree?")awaitinputAsync.confirm("Do you agree?")inputSync.list("You prefere ...",["cats","dogs","rabbits"])awaitinputAsync.list("You prefere ...",["cats","dogs","rabbits"])inputSync.checkbox("Multiselect",["a","b","c"])awaitinputAsync.checkbox("Multiselect",["a","b","c"])

click to watch console screen cast for v1.0.5 (everything should look the same on v2.0.0)

http://www.youtube.com/watch?v=9-GJz1Nlb6I

About

quick-cli

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages