heroku-cli-command
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -5,5 +5,5 @@ 'use strict' | ||
Command: require('./lib/command'), | ||
Topic: require('./lib/topic'), | ||
convertLegacy: require('./lib/legacy'), | ||
mixins: require('./lib/mixins'), | ||
CommandList: require('./lib/command_list') | ||
mixins: require('./lib/mixins') | ||
} |
@@ -7,12 +7,17 @@ 'use strict' | ||
const parse = require('./parse') | ||
const http = require('./http') | ||
const _flags = Symbol('flags') | ||
const _args = Symbol('args') | ||
class Command extends mixins.mix(Object).with(color(), output(), parse()) { | ||
class Command extends mixins.mix(Object).with(color(), output(), parse(), http()) { | ||
constructor (options = {}) { | ||
super(options) | ||
this.options = options | ||
this.argv = options.argv | ||
} | ||
run () { | ||
/** | ||
* actual command run code goes here | ||
*/ | ||
async run () { | ||
throw new Error('must implement abstract class Command') | ||
@@ -25,2 +30,6 @@ } | ||
/** | ||
* get whether or not command is in debug mode | ||
* @returns {number} - 0 if not debugging, otherwise current debug level (1 or 2 usually) | ||
*/ | ||
get debugging () { | ||
@@ -27,0 +36,0 @@ if (this.flags.debug) return this.flags.debug |
@@ -5,2 +5,4 @@ 'use strict' | ||
const mixins = require('./mixins') | ||
const api = require('./mixins/api') | ||
const app = require('./mixins/app') | ||
@@ -21,5 +23,5 @@ module.exports = command => { | ||
NewCommand.mixins = [] | ||
if (command.needsAuth) mixins.auth(NewCommand) | ||
if (command.needsApp) mixins.app(NewCommand) | ||
if (command.needsAuth) mixins.mix(NewCommand).with(api()) | ||
if (command.needsApp) mixins.mix(NewCommand).with(app()) | ||
return NewCommand | ||
} |
@@ -6,15 +6,9 @@ 'use strict' | ||
const stderr = Symbol('stderr') | ||
const write = Symbol('write') | ||
const util = require('util') | ||
const linewrap = require('./linewrap') | ||
const screen = require('./screen') | ||
function errtermwidth () { | ||
if (!process.stderr.isTTY) return 80 | ||
let width = process.stderr.getWindowSize()[0] | ||
return width < 30 ? 30 : width | ||
} | ||
function wrap (msg) { | ||
return linewrap(6, | ||
errtermwidth(), { | ||
screen.errtermwidth(), { | ||
skipScheme: 'ansi-color', | ||
@@ -136,17 +130,2 @@ skip: /^\$ .*$/ | ||
get write () { | ||
if (this[write]) return this[write] | ||
this[write] = (data) => { | ||
if (this[stdout]) this[stdout].push(data) | ||
else if (this[slack]) this[slack].push(data) | ||
else process.stdout.write(data) | ||
} | ||
this[write].error = (data) => { | ||
if (this[stderr]) this[stderr].push(data) | ||
else if (this[slack]) this[slack].push(data) | ||
else process.stderr.write(data) | ||
} | ||
return this[write] | ||
} | ||
styledJSON (obj) { | ||
@@ -207,8 +186,22 @@ let json = JSON.stringify(obj, null, 2) | ||
error (err) { | ||
if (typeof err === 'string') err = new Error(err) | ||
if (this.action.spinner) this.action.done(this.color.bold.red('!')) | ||
if (this.debugging) console.error(err.stack) | ||
else console.error(bangify(wrap(getErrorMessage(err)), this.color.red(arrow))) | ||
if (typeof err === 'string') { | ||
this.action.pause(() => { | ||
if (this[stderr]) this[stderr].push(err) | ||
else if (this[slack]) this[slack].push(err) | ||
else console.error(err) | ||
}) | ||
} else { | ||
if (this.action.spinner) this.action.done(this.color.bold.red('!')) | ||
if (this.debugging) console.error(err.stack) | ||
else console.error(bangify(wrap(getErrorMessage(err)), this.color.red(arrow))) | ||
} | ||
} | ||
warn (message) { | ||
this.action.pause(() => { | ||
if (this.debugging) console.trace(`WARNING: ${message}`) | ||
else console.error(bangify(wrap(message), this.color.yellow(arrow))) | ||
}) | ||
} | ||
showCursor () { | ||
@@ -215,0 +208,0 @@ const ansi = require('ansi-escapes') |
@@ -5,3 +5,3 @@ 'use strict' | ||
const errors = require('./errors') | ||
const screen = require('./screen') | ||
@@ -25,3 +25,2 @@ class Spinner { | ||
this.stream = this.options.stream || process.stderr | ||
this.warnings = [] | ||
} | ||
@@ -59,11 +58,2 @@ | ||
warn (msg) { | ||
if (!this.enabled) { | ||
this.command.write.error(this.command.color.yellow(' !') + '\n' + errors.renderWarning(msg) + '\n' + this.text) | ||
} else { | ||
this.warnings.push(msg) | ||
this._render() | ||
} | ||
} | ||
get status () { | ||
@@ -96,4 +86,3 @@ return this._status | ||
if (this._output) this.clear() | ||
this._output = `${this.text}${this.enabled ? ' ' + this._frame() : ''} ${this.status ? this.status : ''}\n` + | ||
this.warnings.map(w => errors.renderWarning(w) + '\n').join('') | ||
this._output = `${this.text}${this.enabled ? ' ' + this._frame() : ''} ${this.status ? this.status : ''}\n` | ||
this.stream.write(this._output) | ||
@@ -110,3 +99,3 @@ } | ||
get _width () { | ||
return errors.errtermwidth() | ||
return screen.errtermwidth() | ||
} | ||
@@ -113,0 +102,0 @@ |
{ | ||
"name": "heroku-cli-command", | ||
"description": "base Heroku CLI command", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
"bugs": "https://github.com/heroku/heroku-cli-command/issues", | ||
"dependencies": { | ||
@@ -11,7 +13,18 @@ "ansi-escapes": "1.4.0", | ||
"heroku-client": "3.0.0", | ||
"netrc": "0.1.4" | ||
"lodash.maxby": "4.6.0", | ||
"netrc": "0.1.4", | ||
"string": "3.3.3" | ||
}, | ||
"devDependencies": { | ||
"np": "2.12.0" | ||
"chai": "3.5.0", | ||
"mocha": "3.2.0", | ||
"np": "2.12.0", | ||
"nyc": "10.1.2", | ||
"standard": "8.6.0" | ||
}, | ||
"homepage": "https://github.com/heroku/heroku-cli-command", | ||
"keywords": [ | ||
"heroku", | ||
"heroku-cli-plugin" | ||
], | ||
"license": "ISC", | ||
@@ -21,4 +34,10 @@ "main": "index.js", | ||
"scripts": { | ||
"release": "np" | ||
"release": "np", | ||
"test": "nyc mocha && standard" | ||
}, | ||
"standard": { | ||
"ignore": [ | ||
"lib/linewrap.js" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
@heroku-cli/command |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
152249
24
2156
2
1
1
6
0
8
5
2
+ Addedlodash.maxby@4.6.0
+ Addedstring@3.3.3
+ Addedlodash.maxby@4.6.0(transitive)
+ Addedstring@3.3.3(transitive)