eshost-cli
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -35,2 +35,4 @@ #!/usr/bin/env node | ||
.nargs('g', 1) | ||
.describe('tags', 'select hosts by tag') | ||
.nargs('tags', 1) | ||
.describe('c', 'select a config file') | ||
@@ -62,2 +64,4 @@ .alias('c', 'config') | ||
.example('eshost --add d8 d8 path/to/d8 --args "--harmony"') | ||
.example('eshost --add ch ch path/to/ch --tags latest') | ||
.example('eshost --add ch ch path/to/ch --tags latest,greatest') | ||
.example('eshost test.js') | ||
@@ -72,2 +76,3 @@ .example('eshost -e "1+1"') | ||
.example('eshost -h ch-1.?.? test.js') | ||
.example('eshost --tags latest test.js') | ||
.fail(function (msg, err) { | ||
@@ -137,2 +142,28 @@ if (err) { | ||
let hostTags; | ||
if (Array.isArray(argv.tags)) { | ||
hostTags = argv.tags; | ||
} else if (typeof argv.tags === 'string') { | ||
hostTags = argv.tags.split(','); | ||
} | ||
if (hostTags) { | ||
function includesAnyOf(a, b) { | ||
// console.log(`${a} includesAnyOf ${b}`); // TODO (dilijev) remove | ||
for (let x of a) { | ||
if (b.includes(x)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
for (let hostName of Object.keys(config.hosts)) { | ||
let tags = config.hosts[hostName].tags; | ||
if (tags && includesAnyOf(tags, hostTags)) { | ||
hosts.push(hostName); | ||
} | ||
} | ||
} | ||
// if hosts is still empty, get all hosts from config | ||
@@ -166,3 +197,3 @@ if (hosts.length === 0) { | ||
if (argv.add) { | ||
hostManager.add(config, argv.add[0], argv.add[1], argv._[0], argv.args); | ||
hostManager.add(config, argv.add[0], argv.add[1], argv._[0], argv.args, hostTags); | ||
console.log(`Host '${argv.add[0]}' added`); | ||
@@ -169,0 +200,0 @@ process.exit(0); |
@@ -13,3 +13,9 @@ 'use strict'; | ||
var table = new Table({ | ||
head: ['name', 'type', 'path', 'args'] | ||
head: [ | ||
'name', | ||
'type', | ||
'path', | ||
'args', | ||
'tags' | ||
], | ||
}); | ||
@@ -19,3 +25,9 @@ | ||
const host = config.hosts[name]; | ||
table.push([name, host.type, host.path || '', host.args || '']); | ||
table.push([ | ||
name, | ||
host.type, | ||
host.path || '', | ||
host.args || '', | ||
(host.tags || '') + '', | ||
]); | ||
}) | ||
@@ -26,6 +38,6 @@ | ||
exports.add = function add(config, name, type, path, args) { | ||
exports.add = function add(config, name, type, path, args, tags) { | ||
console.log(chalk.grey('Using config ', config.configPath)); | ||
if(config.hosts[name]) { | ||
if (config.hosts[name]) { | ||
console.log(chalk.red(`Host '${name}' already exists`)); | ||
@@ -35,3 +47,3 @@ return; | ||
if(esh.supportedHosts.indexOf(type) === -1) { | ||
if (esh.supportedHosts.indexOf(type) === -1) { | ||
console.log( | ||
@@ -45,7 +57,7 @@ chalk.red( | ||
if(path && !Path.isAbsolute(path)) { | ||
if (path && !Path.isAbsolute(path)) { | ||
path = Path.join(process.cwd(), path); | ||
} | ||
config.hosts[name] = { type, path, args }; | ||
config.hosts[name] = { type, path, args, tags }; | ||
config.save(); | ||
@@ -52,0 +64,0 @@ } |
@@ -9,3 +9,3 @@ module.exports = class Reporter { | ||
static coalesceInto(table, host, result, sep = "\n") { | ||
static coalesceInto(table, host, result, resultsMap /*{result:[...hosts]}*/, sep = "\n") { | ||
let found = false; | ||
@@ -15,3 +15,13 @@ | ||
if (row[1] === result) { | ||
row[0] += sep + host.name; | ||
let hosts = resultsMap[result]; | ||
hosts.push(host); | ||
hosts.sort((a,b) => a.name.localeCompare(b.name)); | ||
let text = hosts[0].name; | ||
hosts.slice(1).forEach((x) => { | ||
text += sep + x.name; | ||
}); | ||
text = text.trim(); | ||
row[0] = text; | ||
found = true; | ||
@@ -23,2 +33,3 @@ break; | ||
if (!found) { | ||
resultsMap[result] = [host]; | ||
table.push([ | ||
@@ -25,0 +36,0 @@ host.name, result |
@@ -8,2 +8,3 @@ const Reporter = require('../Reporter.js'); | ||
this.results = []; | ||
this.resultsMap = {}; | ||
} | ||
@@ -24,3 +25,3 @@ start(text) { | ||
if (this.options.coalesce) { | ||
Reporter.coalesceInto(this.results, host, resultString, ", "); | ||
Reporter.coalesceInto(this.results, host, resultString, this.resultsMap, ", "); | ||
} else { | ||
@@ -27,0 +28,0 @@ printHostResult(host.name, resultString); |
@@ -9,2 +9,3 @@ const Reporter = require('../Reporter.js'); | ||
this.results = new Table(); | ||
this.resultsMap = {}; | ||
} | ||
@@ -28,3 +29,3 @@ | ||
if (this.options.coalesce) { | ||
Reporter.coalesceInto(this.results, host, resultCell); | ||
Reporter.coalesceInto(this.results, host, resultCell, this.resultsMap); | ||
} else { | ||
@@ -31,0 +32,0 @@ this.results.push([ |
{ | ||
"name": "eshost-cli", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Run scripts in any ECMAScript host", | ||
@@ -5,0 +5,0 @@ "bin": { |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14711
436
0