# circle-cli-util

> Set of helpful CLI utilities

Latest version **1.2.0** (published 2016-01-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install circle-cli-util
pnpm add circle-cli-util
yarn add circle-cli-util
bun add circle-cli-util
```

## 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.2.0 |
| Published | 2016-01-16 |
| First published | 2016-01-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | Mark Pundsack |
| Maintainers | markpundsack |

## Links

- npm: https://www.npmjs.com/package/circle-cli-util
- Repository: https://github.com/circleci/circle-cli-util
- Issues: https://github.com/circleci/circle-cli-util/issues
- npm.io page: https://npm.io/package/circle-cli-util

## Dependencies (3)

- [co](https://npm.io/package/co.md) 4.6.0
- [chalk](https://npm.io/package/chalk.md) 1.1.1
- [lodash](https://npm.io/package/lodash.md) 3.10.1

## Recent versions

- 1.2.0 (latest) — 2016-01-16
- 1.0.0 — 2016-01-16

## README

# circle-cli-util

[![Circle CI](https://circleci.com/gh/circleci/circle-cli-util.svg?style=svg)](https://circleci.com/gh/circleci/circle-cli-util)
[![npm version](https://badge.fury.io/js/circle-cli-util.svg)](http://badge.fury.io/js/circle-cli-util)
[![License](https://img.shields.io/npm/l/circle-cli-util.svg)](./LICENSE)
[![Inline docs](http://inch-ci.org/github/circleci/circle-cli-util.svg?branch=master)](http://inch-ci.org/github/circleci/circle-cli-util)

Set of helpful CLI utilities

## Installation

```sh
npm install circle-cli-util --save
```

## Action

```js
let cli      = require('circle-cli-util');
let promise  = circle.projects(project).info();
let projects = yield cli.action('getting project', promise);
console.log(`project name: ${project.name}`);

// getting project... done
// project name: project
```

Note: to use `yield` you need to wrap this in a [co](https://github.com/tj/co) block.

## Prompt

Callback style

```js
let cli = require('circle-cli-util');
cli.prompt('email', {}, function (_, email) {
  console.log(`your email is: ${email}`);
});
```

Promise style

```js
let cli = require('circle-cli-util');
cli.prompt('email', {}).then(function (email) {
  console.log(`your email is: ${email}`);
});
```

Generator style (must be wrapped in a [co](https://github.com/tj/co) block)

```js
let cli   = require('circle-cli-util');
let email = yield cli.prompt('email', {});
console.log(`your email is: ${email}`);
```

**cli.prompt options**

```js
cli.prompt('email', {
  mask: true, // mask input field after submitting
  hide: true // mask characters while entering
});
```

## Confirm App

Supports the same async styles as `prompt()`. Errors if not confirmed.

Basic

```js
let cli = require('circle-cli-util');
yield cli.confirmApp('appname', context.flags.confirm);

// !     WARNING: Destructive Action
// !     This command will affect the app appname
// !     To proceed, type appname or re-run this command with --confirm appname

> appname
```

Custom message

```js
let cli = require('circle-cli-util');
yield cli.confirmApp('appname', context.flags.confirm, 'foo');

// !     foo
// !     To proceed, type appname or re-run this command with --confirm appname

> appname
```

## Errors

```js
let cli = require('circle-cli-util');
cli.error("App not found");
// !    App not found
```

## Warnings

```js
let cli = require('circle-cli-util');
cli.warn("App not found");
// !    App not found
```

## Dates

```js
let cli = require('circle-cli-util');
let d   = new Date();
console.log(cli.formatDate(d));
// 2001-01-01T08:00:00.000Z
```

## Hush

Use hush for verbose logging when `CIRCLE_DEBUG=1`.

```js
let cli = require('circle-cli-util');
cli.hush('foo');
// only prints if CIRCLE_DEBUG is set
```

## Debug

Pretty print an object.

```js
let cli = require('circle-cli-util');
cli.debug({foo: [1,2,3]});
// { foo: [ 1, 2, 3 ] }
```

## Stylized output

Pretty print a header and hash
```js
let cli = require('circle-cli-util');
cli.styledHeader("MyApp");
cli.styledHash({name: "myapp", collaborators: ["user1@example.com", "user2@example.com"]});
```

Produces

```
=== MyApp
Collaborators: user1@example.com
               user1@example.com
Name:          myapp
```

## Table

```js
cli.table([
  {app: 'first-app',  language: 'ruby', dyno_count: 3},
  {app: 'second-app', language: 'node', dyno_count: 2},
], {
  columns: [
    {key: 'app'},
    {key: 'dyno_count', label: 'Dyno Count'},
    {key: 'language', format: language => cli.color.red(language)},
  ]
});
```

Produces:

```
app         Dyno Count  language
──────────  ──────────  ────────
first-app   3           ruby
second-app  2           node
```

## Mocking

Mock stdout and stderr by using `cli.log()` and `cli.error()`.

```js
let cli = require('circle-cli-util');
cli.log('message 1'); // prints 'message 1'
cli.mockConsole();
cli.log('message 2'); // prints nothing
cli.stdout.should.eq('message 2\n');
```

## Command

Used for initializing a plugin command.

It expects you to return a promise chain. This is usually done with [co](https://github.com/tj/co).

```js
let cli     = require('circle-cli-util');
let co      = require('co');
let request = require('request');
module.exports.commands = [
  {
    topic: 'apps',
    command: 'info',
    needsAuth: true,
    needsApp: true,
    run: cli.command(function (context) {
      return co(function* () {
        let projects = yield request.get('https://circleci.com/api/v1/projects');
        console.dir(app);
      });
    })
  }
];
```

With options:

```js
let cli = require('circle-cli-util');
let co  = require('co');
module.exports.commands = [
  {
    topic: 'apps',
    command: 'info',
    needsAuth: true,
    needsApp: true,
    run: cli.command(
      {preauth: true},
      function (context) {
        return co(function* () {
          let projects = yield request.get('https://circleci.com/api/v1/projects');
          console.dir(app);
        });
      }
    )
  }
];
```

## Tests

```sh
npm install
npm test
```

## License

ISC

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