cli-ext
CLI extensions for a rich user interface.
Last updated 3 years ago by buggyorg .
MIT · Original npm · Tarball · package.json
$ cnpm install cli-ext 
SYNC missed versions from official npm registry.

cliExt

A package for cli input handling. This package simplifies the hassle to allow file input, piped input. It even supports editor inputs when no input is given.

Installation

Via npm

npm install cli-ext

Usage

import * as cliExt from 'cli-ext'

// get stdin input or if none is given open an editor
cliExt.input()
.then((contents) => console.log('stdin or editor input: ', contents))

// if the second process argument is a file it opens that file
// otherwise check stdin
// default to an editor if none of the above is set
cliExt.input(process.argv[2])
.then((contents) => console.log(contents))

// opens an editor to edit the file `config.json`
cliExt.edit('./config.json')
.then((json) => ...)

// opens an editor to edit the given text
cliExt.editContent('text to display in the editor')
.then((text) => ...)

// use a function to verify the contents of the input.
// Here we want to ensure that the content is at least 100 characters long
cliExt.input(process.argv[2], {verify: (content) => content.length > 100})
.then((text) => ...)

API

This package exports three methods:

Method Description
.input(file, config) Try to read the file if none is given look for stdin input. If there is no stdin input open the editor specified by the environment variable $EDITOR (default nano). Returns a promise with the resulting text. The configuration config accepts the following keys.

  • fileType: Specify the file type for syntax highlighting in the editor. [Default: '.json']
  • - defaultContent: Specify the contents of the editor if it defaults to the editor. [Default: '']
  • - verify: A function that is used to test the input. If the test fails and the input is specified via a file or stdin, the Promise will be rejected. If the user wrote the contents in an editor .input will prompt the user to abort, or review the contents. [Default: null = constant true].
edit(file, verify) Opens an editor to edit the given file. It is possible to specify a verify function that checks the user input and prompts the user to abort, or review when verify returns false.
editContent(content, verify) Opens an editor with the given content. It is possible to specify a verify function that checks the user input and prompts the user to abort, or review when verify returns false.

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

3 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 2
This Month 2
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (3)

Copyright 2014 - 2017 © taobao.org |