Skip to content

Commit

Permalink
detail: Switch to inverting the cmd to run instead of quoting
Browse files Browse the repository at this point in the history
The idea here is that this way double clicking the command to run will never
pick up backticks. It's also substantially more visible.

I swapped from `ansicolors` to my own `console-control-strings` for this to
get the invert codes.
  • Loading branch information
iarna committed Apr 29, 2018
1 parent 07e1279 commit b9ce234
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
35 changes: 16 additions & 19 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
'use strict'
exports.severityLabel = severityLabel
exports.color = color

const colors = require('ansicolors')
const ccs = require('console-control-strings')

const severityColors = {
critical: colors.magenta,
high: colors.red,
moderate: colors.yellow,
low: function (str) { return str }
function color (name) {
const start = ccs.color(name)
const stop = ccs.color(reset)
return str => start + str + stop
}

const severityLabel = function (sev, withColor) {
if (withColor) {
return severityColors[sev](sev)
}
return sev
const severityColors = {
critical: 'magenta',
high: 'red',
moderate: 'yellow',
low: null
}

const color = function (value, color, withColor) {
if (withColor) {
return colors[color](value)
}
return value
function color (value, colorName, withColor) {
return (colorName && withColor) ? ccs.color(colorName) + value + ccs.color('reset') : value
}

module.exports = {
severityLabel: severityLabel,
color: color
function severityLabel (sev, withColor) {
return color(sev, severityColors[sev], withColor)
}
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"author": "Adam Baldwin",
"license": "ISC",
"dependencies": {
"ansicolors": "^0.3.2",
"ansistyles": "^0.1.3",
"cli-table2": "^0.2.0"
"cli-table2": "^0.2.0",
"console-control-strings": "^1.1.0"
},
"devDependencies": {
"keyfob": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion reporters/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const report = function (data, options) {
if (action.action === 'update' || action.action === 'install') {
const recommendation = getRecommendation(action, config)
const label = action.resolves.length === 1 ? 'vulnerability' : 'vulnerabilities'
log(`\n\n# Run \`${Utils.color(recommendation.cmd, 'red', config.withColor)}\` to resolve ${action.resolves.length} ${label}`)
log(`\n\n# Run ${Utils.color(recommendation.cmd, ['red', 'inverse'], config.withColor)} to resolve ${action.resolves.length} ${label}`)
if (recommendation.isBreaking) {
log(`SEMVER WARNING: Recommended action is a potentially breaking change`)
}
Expand Down
2 changes: 1 addition & 1 deletion test/detail-report-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ tap.test('it generates a detail report with one vuln (review dev dep)', function
tap.test('it generates a detail report with one vuln, no color', function (t) {
return Report(fixtures['one-vuln'], {reporter: 'detail', withColor: false}).then((report) => {
t.match(report.exitCode, 1)
t.match(report.report, /# Run `npm update tough-cookie --depth 6` to resolve 1 vulnerability/)
t.match(report.report, /# Run npm update tough-cookie --depth 6 to resolve 1 vulnerability/)
})
})

Expand Down

0 comments on commit b9ce234

Please sign in to comment.