Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heroku-cli-util

Package Overview
Dependencies
Maintainers
2
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heroku-cli-util - npm Package Compare versions

Comparing version 1.11.0 to 2.0.0

util.js

4

cli.js
var console = require('./console');
var errors = require('./errors');
var config = require('./config');
var prompt = require('./prompt');

@@ -12,4 +13,5 @@ exports.run = require('./run');

exports.console = console;
exports.prompt = prompt.prompt;
exports.confirmApp = prompt.confirmApp;
exports.preauth = require('./preauth');
exports.prompt = require('./prompt');
exports.command = require('./command');

@@ -16,0 +18,0 @@

@@ -6,36 +6,2 @@ 'use strict';

function handleErr (context) {
return function (err) {
if (err.body) {
// API error
if (err.body.message) {
errors.error(err.body.message);
} else if (err.body.error) {
errors.error(err.body.error);
}
} else {
// Unhandled error
if (err.message) {
errors.error(err.message);
} else {
errors.error(err);
}
if (err.stack) {
var logPath = context.herokuDir + '/error.log';
var fs = require('fs');
var log = function (line) {
var d = new Date().toISOString()
.replace(/T/, ' ')
.replace(/-/g, '/')
.replace(/\..+/, '');
fs.appendFileSync(logPath, d + ' ' + line + '\n');
};
log(err.stack);
errors.error(`See ${logPath}` + logPath + ' for more info.');
}
}
process.exit(1);
};
}
module.exports = function command (fn) {

@@ -50,4 +16,4 @@ return function (context) {

yield fn(context, heroku);
}).catch(handleErr(context));
}).catch(errors.handleErr(context));
};
};
'use strict';
var chalk = require('chalk');
var console = require('./console');
let console = require('./console');
let linewrap = require('linewrap');
function wrap (msg) {
return linewrap(6,
process.stderr.getWindowSize()[0], {
skipScheme: 'ansi-color'
})(msg);
}
function bangify (msg) {
let lines = msg.split('\n');
for(let i=0; i<lines.length; i++) {
let line = lines[i];
lines[i] = ' !' + line.substr(2,line.length);
}
return lines.join('\n');
}
function error (msg) {
console.error(' ' + chalk.bgRed('!') + ' ' + msg);
console.error(bangify(wrap(msg)));
}
function warn (msg) {
console.error(' ' + chalk.bgYellow('!') + ' ' + msg);
console.error(bangify(wrap(msg)));
}
module.exports.error = error;
module.exports.warn = warn;
function handleErr (context) {
return function (err) {
if (err.body) {
// API error
if (err.body.message) {
error(err.body.message);
} else if (err.body.error) {
error(err.body.error);
}
} else {
// Unhandled error
if (err.message) {
error(err.message);
} else {
error(err);
}
if (err.stack) {
var logPath = context.herokuDir + '/error.log';
var fs = require('fs');
var log = function (line) {
var d = new Date().toISOString()
.replace(/T/, ' ')
.replace(/-/g, '/')
.replace(/\..+/, '');
fs.appendFileSync(logPath, d + ' ' + line + '\n');
};
log(err.stack);
error(`See ${logPath}` + logPath + ' for more info.');
}
}
process.exit(1);
};
}
module.exports.error = error;
module.exports.warn = warn;
module.exports.handleErr = handleErr;
{
"name": "heroku-cli-util",
"version": "1.11.0",
"version": "2.0.0",
"description": "Set of helpful CLI utilities",

@@ -29,4 +29,5 @@ "main": "cli.js",

"columnify": "^1.4.1",
"heroku-client": "^1.10.0"
"heroku-client": "^1.10.0",
"linewrap": "^0.2.1"
}
}
'use strict';
module.exports = function prompt (name, cb) {
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stderr.write(`${name}: `);
process.stdin.once('data', function (data) {
process.stdin.pause();
data = data.trim();
if (data === '') {
return prompt(name, cb);
let chalk = require('chalk');
let errors = require('./errors');
let util = require('./util');
function prompt (name) {
return new Promise(function (fulfill) {
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stderr.write(name ? name + ': ' : '> ');
process.stdin.once('data', function (data) {
process.stdin.pause();
data = data.trim();
if (data === '') {
fulfill(prompt(name));
} else {
fulfill(data);
}
});
});
}
function confirmApp (app, confirm, message) {
return new Promise(function (fulfill, reject) {
if (confirm) {
if (confirm === app) {
return fulfill();
}
return reject(`Confirmation ${chalk.bold.red(confirm)} did not match ${chalk.bold.red(app)}. Aborted.`);
}
cb(data);
if (!message) {
message = `WARNING: Destructive Action\nThis command will affect the app ${chalk.bold.red(app)}`;
}
errors.warn(message);
errors.warn(`To proceed, type ${chalk.bold.red(app)} or re-run this command with ${chalk.bold.red('--confirm', app)}`);
console.error();
prompt().then(function (confirm) {
if (confirm === app) {
return fulfill();
}
return reject(`Confirmation did not match ${chalk.bold.red(app)}. Aborted.`);
});
});
};
}
exports.prompt = util.promiseOrCallback(prompt);
exports.confirmApp = util.promiseOrCallback(confirmApp);

@@ -17,5 +17,7 @@ # heroku-cli-util

Callback style
```js
var h = require('heroku-cli-util');
h.prompt('email', function (email) {
h.prompt('email', function (_, email) {
console.log(`your email is: ${email}`);

@@ -25,6 +27,52 @@ });

## Errors (display in red)
Promise style
```js
var h = require('heroku-cli-util');
h.prompt('email').then(function (email) {
console.log(`your email is: ${email}`);
});
```
Generator style (must be wrapped in h.command() or co block)
```js
var h = require('heroku-cli-util');
var email = yield h.prompt('email');
console.log(`your email is: ${email}`);
```
## Confirm App
Supports the same async styles as `prompt()`. Errors if not confirmed.
Basic
```js
var h = require('heroku-cli-util');
yield h.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
var h = require('heroku-cli-util');
yield h.confirmApp('appname', context.flags.confirm, 'foo');
// ! foo
// ! To proceed, type appname or re-run this command with --confirm appname
> appname
```
## Errors
```js
var h = require('heroku-cli-util');
h.error("App not found");

@@ -34,3 +82,3 @@ // ! App not found

## Warnings (display in yellow)
## Warnings

@@ -37,0 +85,0 @@ ```js

@@ -12,3 +12,3 @@ require('chai').should();

errors.error('foobar');
console.stderr.should.contain('\u001b[31m ! foobar\u001b[39m');
console.stderr.should.contain(' \u001b[41m!\u001b[49m foobar\n');
});

@@ -18,4 +18,4 @@

errors.warn('foobar');
console.stderr.should.contain('\u001b[33m ! foobar\u001b[39m\n');
console.stderr.should.contain(' \u001b[43m!\u001b[49m foobar\n');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc