8.0.12 • Published 4 years ago

heroku-cli-util v8.0.12

Weekly downloads
93,266
License
ISC
Repository
github
Last release
4 years ago

heroku-cli-util Circle CI

Code Climate Test Coverage npm version License

Set of helpful CLI utilities

Installation

npm install heroku-cli-util --save

Action

let cli = require('heroku-cli-util');
yield cli.action('restarting dynos', co(function* () {
  let app = yield heroku.get(`/apps/${context.app}`);
  yield heroku.request({method: 'DELETE', path: `/apps/${app.name}/dynos`});
}));

// restarting dynos... done

Prompt

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

cli.prompt options

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

let cli = require('heroku-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

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

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

> appname

Note that you will still need to define a confirm flag for your command.

Errors

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

Warnings

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

Dates

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

Hush

Use hush for verbose logging when HEROKU_DEBUG=1.

let cli = require('heroku-cli-util');
cli.hush('foo');
// only prints if HEROKU_DEBUG is set

Debug

Pretty print an object.

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

Stylized output

Pretty print a header, hash, and JSON

let cli = require('heroku-cli-util');
cli.styledHeader("MyApp");
cli.styledHash({name: "myapp", collaborators: ["user1@example.com", "user2@example.com"]});
cli.styledJSON({name: "myapp"});

Produces

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

{
  "name": "myapp"
}

Table

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

Linewrap

Used to indent output with wrapping around words:

cli.log(cli.linewrap(2, 10, 'this is text is longer than 10 characters'));
// Outputs:
//
// this
// text is
//  longer
//  than 10
//  characters`);

Useful with process.stdout.columns || 80.

Open Web Browser

yield cli.open('https://github.com');

HTTP calls

heroku-cli-util includes an instance of got that will correctly use HTTP proxies.

let cli = require('heroku-cli-util');
let rsp = yield cli.got('https://google.com');

Mocking

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

let cli = require('heroku-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. give you an auth'ed instance of heroku-client and cleanly handle API exceptions.

It expects you to return a promise chain. This is usually done with co.

let cli = require('heroku-cli-util');
let co  = require('co');
module.exports.commands = [
  {
    topic: 'apps',
    command: 'info',
    needsAuth: true,
    needsApp: true,
    run: cli.command(function (context, heroku) {
      return co(function* () {
        let app = yield heroku.get(`/apps/${context.app}`);
        console.dir(app);
      });
    })
  }
];

With options:

let cli = require('heroku-cli-util');
let co  = require('co');
module.exports.commands = [
  {
    topic: 'apps',
    command: 'info',
    needsAuth: true,
    needsApp: true,
    run: cli.command(
      {preauth: true},
      function (context, heroku) {
        return co(function* () {
          let app = yield heroku.get(`/apps/${context.app}`);
          console.dir(app);
        });
      }
    )
  }
];

If the command has a two_factor API error, it will ask the user for a 2fa code and retry. If you set preauth: true it will preauth against the current app instead of just setting the header on an app. (This is necessary if you need to do more than 1 API call that will require 2fa)

Tests

npm install
npm test

License

ISC

csa-cli@heroku/csa-clischedulerctl@infinitebrahmanuniverse/nolb-her@everything-registry/sub-chunk-1841write-only-config-varstme-toolsteselagen@heroku-cli/plugin-ps-exec@heroku-cli/plugin-redis@heroku-cli/plugin-redis-v5@heroku-cli/plugin-run-v5@heroku-cli/plugin-spaces@heroku-cli/plugin-webhooks-v5@heroku-cli/plugin-devcenter@heroku-cli/oauth@heroku-cli/plugin-addons@heroku-cli/plugin-addons-v5@heroku-cli/plugin-apps-v5@heroku-cli/plugin-buildpack-registry@heroku-cli/plugin-buildpacks@heroku-cli/plugin-container-registry@heroku-cli/heroku-builds@heroku-cli/heroku-exec-util@heroku-cli/plugin-certs-v5@heroku-cli/plugin-ci-v5@heroku-cli/plugin-java@heroku-cli/plugin-local-v5@heroku-cli/plugin-oauth-v5@heroku-cli/plugin-orgs@heroku-cli/plugin-orgs-v5@heroku-cli/plugin-pg@heroku-cli/plugin-pg-v5@heroku-cli/plugin-pipelines@heroku-cli/plugin-pipelines-v5odaseva-sfdxdestroy-temp-appssalesforce-lightning-clisb-apollosfdx-msm-pluginsfdx-code-gensfdx-oss-pluginskilljar-heroku-forkcodeblox-cli@fastly/heroku-pluginforce-cliforce-language-services@heroku-cli/plugin-container-registry-v5apollo-persisted-hashcake-jsarc-apollo@apollographql/cliadvanced-schedulerbilling-alarm@craigrmccown/apolloletsencrypt-heroku-pluginplugin-buildpack-registryplugin-container-registrydockherodockhero1csa-cli-pluginfwc-heroku-fork@jclem/heroku-pg-pgcli@hyperoslo/heroku-billing@hyperoslo/heroku-pg-filterheroku-accountsheroku-adept-scaleheroku-appsheroku-audit-trailherokuheroku-2faheroku-jmxheroku-kafkaheroku-localheroku-cli-releases-diffheroku-cli-staticheroku-cli-static-realhqheroku-cli-tinyadminheroku-configheroku-config-diffheroku-config-editorheroku-browseheroku-buildkitsheroku-buildsheroku-certsheroku-certs-acmheroku-chartbeatheroku-ciheroku-cli-addonsheroku-cli-apiheroku-dockerheroku-enterpriseheroku-exec-utilheroku-fastlyheroku-forkheroku-fork-finheroku-githeroku-guvscaleheroku-cli-buildkitsheroku-cli-buildpacks
8.0.12

4 years ago

8.0.11

5 years ago

8.0.10

6 years ago

8.0.9

6 years ago

8.0.8

6 years ago

8.0.7

6 years ago

8.0.6

6 years ago

8.0.5

6 years ago

8.0.4

6 years ago

8.0.3

6 years ago

8.0.2

6 years ago

8.0.1

6 years ago

8.0.0

6 years ago

6.2.13

6 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.2.12

6 years ago

6.2.11

6 years ago

6.2.10

7 years ago

6.2.9

7 years ago

6.2.8

7 years ago

6.2.7

7 years ago

6.2.6

7 years ago

6.2.5

7 years ago

6.2.4

7 years ago

6.2.3

7 years ago

6.2.2

7 years ago

6.2.1

7 years ago

6.2.0

7 years ago

6.1.17

7 years ago

6.1.16

7 years ago

6.1.15

7 years ago

6.1.14

7 years ago

6.1.13

7 years ago

6.1.12

7 years ago

6.1.11

7 years ago

6.1.10

7 years ago

6.1.9

7 years ago

6.1.8

7 years ago

6.1.7

7 years ago

6.1.6

7 years ago

6.1.5

7 years ago

6.1.4

7 years ago

6.1.3

7 years ago

6.1.2

7 years ago

6.1.1

7 years ago

6.1.0

7 years ago

6.0.16

7 years ago

6.0.15

8 years ago

6.0.14

8 years ago

6.0.13

8 years ago

6.0.12

8 years ago

6.0.11

8 years ago

6.0.10

8 years ago

6.0.9

8 years ago

6.0.8

8 years ago

6.0.7

8 years ago

6.0.6

8 years ago

6.0.5

8 years ago

6.0.4

8 years ago

6.0.3

8 years ago

6.0.2

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.10.12

8 years ago

5.10.11

8 years ago

5.10.10

8 years ago

5.10.9

8 years ago

5.10.8

8 years ago

5.10.7

8 years ago

5.10.6

8 years ago

5.10.5

8 years ago

5.10.4

8 years ago

5.10.3

8 years ago

5.10.2

8 years ago

5.10.1

8 years ago

5.10.0

8 years ago

5.9.3

8 years ago

5.9.2

8 years ago

5.9.1

8 years ago

5.9.0

8 years ago

5.8.4

8 years ago

5.8.3

8 years ago

5.8.2

8 years ago

5.8.1

8 years ago

5.8.0

8 years ago

5.7.4

8 years ago

5.7.3

8 years ago

5.7.2

8 years ago

5.7.1

8 years ago

5.7.0

8 years ago

5.6.3

8 years ago

5.6.2

8 years ago

5.6.1

8 years ago

5.6.0

8 years ago

5.5.0

8 years ago

5.4.13

9 years ago

5.4.12

9 years ago

5.4.11

9 years ago

5.4.10

9 years ago

5.4.9

9 years ago

5.4.8

9 years ago

5.4.7

9 years ago

5.4.6

9 years ago

5.4.5

9 years ago

5.4.4

9 years ago

5.4.3

9 years ago

5.4.2

9 years ago

5.4.1

9 years ago

5.4.0

9 years ago

5.3.0

9 years ago

5.2.1

9 years ago

5.2.0

9 years ago

5.1.0

9 years ago

5.0.2

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.0.3

9 years ago

4.0.2

9 years ago

4.0.1

9 years ago

4.0.0

9 years ago

3.6.7

9 years ago

3.6.6

9 years ago

3.6.5

9 years ago

3.6.4

9 years ago

3.6.2

9 years ago

3.6.1

9 years ago

3.6.0

9 years ago

3.5.2

9 years ago

3.5.1

9 years ago

3.5.0

9 years ago

3.4.0

9 years ago

3.2.0

9 years ago

3.1.0

9 years ago

3.0.0

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.11.0

9 years ago

1.10.4

9 years ago

1.10.3

9 years ago

1.10.2

9 years ago

1.10.1

9 years ago

1.10.0

9 years ago

1.9.0

9 years ago

1.8.1

9 years ago

1.8.0

9 years ago

1.7.0

9 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago