eshost-cli
Advanced tools
Comparing version 7.5.2 to 7.6.0
@@ -11,2 +11,3 @@ #!/usr/bin/env node | ||
const esh = require('eshost'); | ||
const styles = require('ansi-styles'); | ||
const Table = require('cli-table'); | ||
@@ -51,2 +52,5 @@ const uniqueTempDir = require('unique-temp-dir'); | ||
.alias('coalesce', 's') | ||
.describe('color', 'specify the color to use in output, eg. --color.error red --color.header blue') | ||
.describe('no-color', 'do not colorize output') | ||
.boolean('no-color') | ||
.describe('showSource', 'show input source') | ||
@@ -215,2 +219,3 @@ .boolean('showSource') | ||
coalesce: argv.coalesce, | ||
color: { error: 'magentaBright', header: 'grey', ...(argv.color || {}) }, | ||
showSource: argv.showSource, | ||
@@ -220,2 +225,14 @@ unanimous: argv.unanimous | ||
if (argv.noColors) { | ||
reporterOptions.color = false; | ||
} | ||
let invalidColor = Object.values(reporterOptions.color).find(color => !styles[color]); | ||
if (invalidColor) { | ||
console.log(`Invalid color or style: "${invalidColor}"\n`); | ||
console.log(`Choose from:\n${Object.keys(styles).map(style => `- ${style}\n`).join('')}`); | ||
process.exit(1); | ||
} | ||
let reporter; | ||
@@ -229,4 +246,7 @@ if (argv.table) { | ||
if (argv.list || argv.add || argv.edit || argv.delete || | ||
argv['delete-all'] || argv['configure-esvu'] || argv['configure-jsvu']) { | ||
console.log(chalk.grey(`Using config "${config.configPath}"`)); | ||
argv['delete-all'] || argv.configureEsvu || argv.configureJsvu) { | ||
const message = `Using config "${config.configPath}"`; | ||
console.log( | ||
argv.noColors ? message : chalk.grey(message) | ||
); | ||
} | ||
@@ -273,4 +293,4 @@ // list available hosts | ||
if (argv['configure-esvu'] || argv['configure-jsvu']) { | ||
const vu = argv['configure-esvu'] | ||
if (argv.configureEsvu || argv.configureJsvu) { | ||
const vu = argv.configureEsvu | ||
? 'esvu' | ||
@@ -381,3 +401,6 @@ : 'jsvu'; | ||
}).catch(e => { | ||
console.error(chalk.red(`Failure attempting to eval script in agent: ${e.stack}`)); | ||
const message = `Failure attempting to eval script in agent: ${e.stack}`; | ||
console.error( | ||
argv.noColors ? message : chalk.red(message) | ||
); | ||
}); | ||
@@ -384,0 +407,0 @@ } |
@@ -16,3 +16,3 @@ 'use strict'; | ||
if (this.options.showSource) { | ||
Reporter.printSource(source); | ||
this.printSource(source); | ||
} | ||
@@ -24,3 +24,5 @@ } | ||
if (error) { | ||
resultCell += `\n${chalk.red(`${error.name}: ${error.message}`)}`; | ||
resultCell += this.options.color | ||
? `\n${chalk[this.options.color.error](`${error.name}: ${error.message}`)}` | ||
: `\n${error.name}: ${error.message}`; | ||
} | ||
@@ -52,2 +54,12 @@ resultCell = resultCell.replace(/\r/g, ''); | ||
printSource(source) { | ||
const header = '## Source'; | ||
console.log( | ||
this.options.color | ||
? chalk[this.options.color.header](header) | ||
: header | ||
); | ||
console.log(`${source}\n`); | ||
} | ||
static coalesce(records) { | ||
@@ -63,7 +75,2 @@ const resultsMap = new Map(); | ||
} | ||
static printSource(source) { | ||
console.log(chalk.blue('## Source')); | ||
console.log(`${source}\n`); | ||
} | ||
} |
@@ -14,3 +14,3 @@ const Reporter = require('../Reporter.js'); | ||
const joinedHosts = hosts.join(", ").trim(); | ||
printHostResult(joinedHosts, resultString); | ||
this.printHostResult(joinedHosts, resultString); | ||
} | ||
@@ -23,3 +23,3 @@ | ||
this.results.forEach(row => { | ||
printHostResult(row[0], row[1]); | ||
this.printHostResult(row[0], row[1]); | ||
}); | ||
@@ -29,7 +29,11 @@ } | ||
} | ||
printHostResult(name, result) { | ||
const header = `#### ${name}`; | ||
console.log( | ||
this.options.color | ||
? chalk[this.options.color.header](header) | ||
: header | ||
); | ||
console.log(`${result}\n`); | ||
} | ||
} | ||
function printHostResult(name, result) { | ||
console.log(chalk.blue(`#### ${name}`)); | ||
console.log(`${result}\n`); | ||
} |
{ | ||
"name": "eshost-cli", | ||
"version": "7.5.2", | ||
"version": "7.6.0", | ||
"description": "Run scripts in any ECMAScript host", | ||
@@ -9,3 +9,4 @@ "bin": { | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"ansi-styles": "^4.2.1", | ||
"chalk": "^4.1.0", | ||
"cli-table": "^0.3.1", | ||
@@ -12,0 +13,0 @@ "configstore": "^1.4.0", |
32514
708
9
+ Addedansi-styles@^4.2.1
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedsupports-color@2.0.0(transitive)
Updatedchalk@^4.1.0