# cli-ext

> CLI extensions for a rich user interface.

Latest version **1.1.0** (published 2016-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install cli-ext
pnpm add cli-ext
yarn add cli-ext
bun add cli-ext
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-12-16 |
| First published | 2016-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Maximilian Klein |
| Maintainers | buggyorg |
| Keywords | CLI |

## Links

- npm: https://www.npmjs.com/package/cli-ext
- npm.io page: https://npm.io/package/cli-ext

## Dependencies (3)

- [tempfile](https://npm.io/package/tempfile.md) ^1.1.1
- [get-stdin](https://npm.io/package/get-stdin.md) ^5.0.1
- [prompt-promise](https://npm.io/package/prompt-promise.md) ^1.0.3

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-12-16
- 1.0.1 — 2016-12-16
- 1.0.0 — 2016-11-19

## README

# 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

```js
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.<br><br><ul><li>`fileType`: Specify the file type for syntax highlighting in the editor. [Default: '.json']<li> - `defaultContent`: Specify the contents of the editor if it defaults to the editor. [Default: '']<li> - `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]. |</ul> 
| `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`. |

---
_Source: https://npm.io/package/cli-ext · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
