cli-engine-command
Advanced tools
Comparing version 8.0.15 to 9.0.0-ts.0
@@ -1,119 +0,103 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _parser = require('./parser'); | ||
var _parser2 = _interopRequireDefault(_parser); | ||
var _package = require('../package.json'); | ||
var _package2 = _interopRequireDefault(_package); | ||
var _cliEngineConfig = require('cli-engine-config'); | ||
var _httpCall = require('http-call'); | ||
var _httpCall2 = _interopRequireDefault(_httpCall); | ||
var _help = require('./help'); | ||
var _help2 = _interopRequireDefault(_help); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// eslint-disable-line | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const cli_flags_1 = require("cli-flags"); | ||
const cli_engine_config_1 = require("cli-engine-config"); | ||
const http_call_1 = require("http-call"); | ||
const help_1 = require("./help"); | ||
const util_1 = require("util"); | ||
const pjson = require('../package.json'); | ||
class Command { | ||
static get id() { | ||
let cmd = []; | ||
if (this.topic) cmd.push(this.topic); | ||
if (this.command) cmd.push(this.command); | ||
return cmd.join(':'); | ||
} | ||
/** | ||
* instantiate and run the command setting {mock: true} in the config (shorthand method) | ||
*/ | ||
static async mock(...argv) { | ||
argv.unshift('argv0', 'cmd'); | ||
return this.run({ argv, mock: true }); | ||
} | ||
/** | ||
* instantiate and run the command | ||
*/ | ||
static async run(config) { | ||
const cmd = new this({ config }); | ||
try { | ||
await cmd.init(); | ||
await cmd.run(); | ||
await cmd.out.done(); | ||
} catch (err) { | ||
cmd.out.error(err); | ||
constructor(options = {}) { | ||
this.hidden = false; | ||
this.aliases = []; | ||
this.strict = true; | ||
this.variableArgs = false; | ||
this.Flags = {}; | ||
this.Args = []; | ||
this._version = pjson.version; | ||
this.config = cli_engine_config_1.buildConfig(options.config); | ||
this.argv = this.config.argv; | ||
const { CLI } = require('cli-ux'); | ||
this.cli = new CLI({ mock: this.config.mock }); | ||
this.http = http_call_1.HTTP.defaults({ | ||
headers: { | ||
'user-agent': `${this.config.name}/${this.config.version} (${this.config.platform}-${this.config | ||
.arch}) node-${process.version}`, | ||
}, | ||
}); | ||
} | ||
return cmd; | ||
} | ||
constructor(options = {}) { | ||
this.flags = {}; | ||
this.args = {}; | ||
this.config = (0, _cliEngineConfig.buildConfig)(options.config); | ||
this.argv = this.config.argv; | ||
const { CLI } = require('cli-ux'); | ||
this.out = new CLI({ mock: this.config.mock }); | ||
this.out.color = require('./color').color; | ||
this.http = _httpCall2.default.defaults({ | ||
headers: { | ||
'user-agent': `${this.config.name}/${this.config.version} (${this.config.platform}-${this.config.arch}) node-${process.version}` | ||
} | ||
}); | ||
} | ||
async init() { | ||
const parser = new _parser2.default({ | ||
flags: this.constructor.flags || {}, | ||
args: this.constructor.args || [], | ||
variableArgs: this.constructor.variableArgs, | ||
cmd: this | ||
}); | ||
const { argv, flags, args } = await parser.parse({ flags: this.flags, argv: this.argv.slice(2) }); | ||
this.flags = flags; | ||
this.argv = argv; | ||
this.args = args; | ||
} | ||
// prevent setting things that need to be static | ||
/** | ||
* actual command run code goes here | ||
*/ | ||
async run(...rest) {} | ||
get stdout() { | ||
return this.out.stdout.output; | ||
} | ||
get stderr() { | ||
return this.out.stderr.output; | ||
} | ||
static buildHelp(config) { | ||
let help = new _help2.default(config); | ||
return help.command(this); | ||
} | ||
static buildHelpLine(config) { | ||
let help = new _help2.default(config); | ||
return help.commandLine(this); | ||
} | ||
get id() { | ||
let cmd = []; | ||
if (this.topic) | ||
cmd.push(this.topic); | ||
if (this.command) | ||
cmd.push(this.command); | ||
return cmd.join(':'); | ||
} | ||
static mock(...argv) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
argv.unshift('argv0', 'cmd'); | ||
return this.run({ argv, mock: true }); | ||
}); | ||
} | ||
static run(config) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const cmd = new this({ config }); | ||
try { | ||
yield cmd.init(); | ||
yield cmd.run(); | ||
yield cmd.out.done(); | ||
} | ||
catch (err) { | ||
cmd.out.error(err); | ||
} | ||
return cmd; | ||
}); | ||
} | ||
get out() { | ||
util_1.deprecate(() => { }, 'this.out is deprecated, use this.cli'); | ||
return this.cli; | ||
} | ||
init() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.variableArgs) { | ||
util_1.deprecate(() => { }, 'variableArgs is deprecated. Use strict = true instead.'); | ||
} | ||
const { argv, flags, args } = yield cli_flags_1.parse({ | ||
flags: this.Flags, | ||
args: this.Args, | ||
strict: this.strict !== false && !this.variableArgs, | ||
argv: this.argv.slice(2), | ||
}); | ||
this.flags = flags; | ||
this.argv = argv; | ||
this.args = args; | ||
}); | ||
} | ||
run() { | ||
return __awaiter(this, void 0, void 0, function* () { }); | ||
} | ||
get stdout() { | ||
return this.cli.stdout.output; | ||
} | ||
get stderr() { | ||
return this.cli.stderr.output; | ||
} | ||
buildHelp(config) { | ||
let help = new help_1.Help(config); | ||
return help.command(this); | ||
} | ||
buildHelpLine(config) { | ||
let help = new help_1.Help(config); | ||
return help.commandLine(this); | ||
} | ||
} | ||
exports.default = Command; | ||
Command.aliases = []; | ||
Command.variableArgs = false; | ||
Command.args = []; | ||
Command._version = _package2.default.version; | ||
exports.Command = Command; |
170
lib/help.js
@@ -1,97 +0,85 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _screen = require('./screen'); | ||
var _color = require('./color'); | ||
function linewrap(length, s) { | ||
const linewrap = require('@heroku/linewrap'); | ||
return linewrap(length, _screen.stdtermwidth, { | ||
skipScheme: 'ansi-color' | ||
})(s).trim(); | ||
} | ||
function renderList(items) { | ||
const S = require('string'); | ||
const max = require('lodash.maxby'); | ||
let maxLength = max(items, '[0].length')[0].length; | ||
let lines = items.map(i => { | ||
let left = i[0]; | ||
let right = i[1]; | ||
if (!right) return left; | ||
left = `${S(left).padRight(maxLength)}`; | ||
right = linewrap(maxLength + 2, right); | ||
return `${left} ${right}`; | ||
}); | ||
return lines.join('\n'); | ||
} | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const list_1 = require("cli-ux/lib/list"); | ||
const chalk = require("chalk"); | ||
function buildUsage(command) { | ||
if (command.usage) return command.usage.trim(); | ||
let cmd = command.id; | ||
if (!command.args) return cmd.trim(); | ||
let args = command.args.map(renderArg); | ||
return `${cmd} ${args.join(' ')}`.trim(); | ||
if (command.usage) | ||
return command.usage.trim(); | ||
let cmd = command.id; | ||
if (!command.Args) | ||
return cmd.trim(); | ||
let args = command.Args.map(renderArg); | ||
return `${cmd} ${args.join(' ')}`.trim(); | ||
} | ||
function renderArg(arg) { | ||
let name = arg.name.toUpperCase(); | ||
if (arg.required !== false && arg.optional !== true) return `${name}`;else return `[${name}]`; | ||
let name = arg.name.toUpperCase(); | ||
if (arg.required !== false && arg.optional !== true) | ||
return `${name}`; | ||
else | ||
return `[${name}]`; | ||
} | ||
class Help { | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
command(cmd) { | ||
let flags = Object.entries(cmd.flags || {}).filter(([name, flag]) => !flag.hidden); | ||
let args = (cmd.args || []).filter(a => !a.hidden); | ||
let hasFlags = flags.length ? ` ${_color.color.blue('[flags]')}` : ''; | ||
let usage = `${_color.color.bold('Usage:')} ${this.config.bin} ${buildUsage(cmd)}${hasFlags}\n`; | ||
return [usage, cmd.description ? `\n${_color.color.bold(cmd.description.trim())}\n` : '', this.renderAliases(cmd.aliases), this.renderArgs(args), this.renderFlags(flags), cmd.help ? `\n${cmd.help.trim()}\n` : ''].join(''); | ||
} | ||
commandLine(cmd) { | ||
return [buildUsage(cmd), cmd.description ? _color.color.dim(cmd.description) : null]; | ||
} | ||
renderAliases(aliases) { | ||
if (!aliases || !aliases.length) return ''; | ||
let a = aliases.map(a => ` $ ${this.config.bin} ${a}`).join('\n'); | ||
return `\n${_color.color.blue('Aliases:')}\n${a}\n`; | ||
} | ||
renderArgs(args) { | ||
if (!args.find(f => f.description)) return ''; | ||
return '\n' + renderList(args.map(a => { | ||
return [a.name.toUpperCase(), a.description ? _color.color.dim(a.description) : null]; | ||
})) + '\n'; | ||
} | ||
renderFlags(flags) { | ||
if (!flags.length) return ''; | ||
flags.sort((a, b) => { | ||
if (a[1].char && !b[1].char) return -1; | ||
if (b[1].char && !a[1].char) return 1; | ||
if (a[0] < b[0]) return -1; | ||
return b[0] < a[0] ? 1 : 0; | ||
}); | ||
return `\n${_color.color.blue('Flags:')}\n` + renderList(flags.map(([name, f]) => { | ||
let label = []; | ||
if (f.char) label.push(`-${f.char}`); | ||
if (name) label.push(` --${name}`); | ||
let usage = f.parse ? ` ${name.toUpperCase()}` : ''; | ||
let description = f.description || ''; | ||
if (f.required || f.optional === false) description = `(required) ${description}`; | ||
return [` ${label.join(',').trim()}` + usage, description ? _color.color.dim(description) : null]; | ||
})) + '\n'; | ||
} | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
command(cmd) { | ||
let flags = Object.entries(cmd.Flags || {}).filter(([, flag]) => !flag.hidden); | ||
let args = (cmd.Args || []).filter(a => !a.hidden); | ||
let hasFlags = flags.length ? ` ${chalk.blue('[flags]')}` : ''; | ||
let usage = `${chalk.bold('Usage:')} ${this.config.bin} ${buildUsage(cmd)}${hasFlags}\n`; | ||
return [ | ||
usage, | ||
cmd.description ? `\n${chalk.bold(cmd.description.trim())}\n` : '', | ||
this.renderAliases(cmd.aliases), | ||
this.renderArgs(args), | ||
this.renderFlags(flags), | ||
cmd.help ? `\n${cmd.help.trim()}\n` : '', | ||
].join(''); | ||
} | ||
commandLine(cmd) { | ||
return [buildUsage(cmd), cmd.description ? chalk.dim(cmd.description) : null]; | ||
} | ||
renderAliases(aliases) { | ||
if (!aliases || !aliases.length) | ||
return ''; | ||
let a = aliases.map(a => ` $ ${this.config.bin} ${a}`).join('\n'); | ||
return `\n${chalk.blue('Aliases:')}\n${a}\n`; | ||
} | ||
renderArgs(args) { | ||
if (!args.find(f => !!f.description)) | ||
return ''; | ||
return ('\n' + | ||
list_1.renderList(args.map(a => { | ||
return [a.name.toUpperCase(), a.description ? chalk.dim(a.description) : null]; | ||
})) + | ||
'\n'); | ||
} | ||
renderFlags(flags) { | ||
if (!flags.length) | ||
return ''; | ||
flags.sort((a, b) => { | ||
if (a[1].char && !b[1].char) | ||
return -1; | ||
if (b[1].char && !a[1].char) | ||
return 1; | ||
if (a[0] < b[0]) | ||
return -1; | ||
return b[0] < a[0] ? 1 : 0; | ||
}); | ||
return (`\n${chalk.blue('Flags:')}\n` + | ||
list_1.renderList(flags.map(([name, f]) => { | ||
let label = []; | ||
if (f.char) | ||
label.push(`-${f.char}`); | ||
if (name) | ||
label.push(` --${name}`); | ||
let usage = f.type === 'option' ? ` ${name.toUpperCase()}` : ''; | ||
let description = f.description || ''; | ||
if (f.required) | ||
description = `(required) ${description}`; | ||
return [` ${label.join(',').trim()}` + usage, description ? chalk.dim(description) : null]; | ||
})) + | ||
'\n'); | ||
} | ||
} | ||
exports.default = Help; | ||
exports.Help = Help; |
@@ -1,40 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _command = require('./command'); | ||
Object.defineProperty(exports, 'default', { | ||
enumerable: true, | ||
get: function () { | ||
return _interopRequireDefault(_command).default; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'Command', { | ||
enumerable: true, | ||
get: function () { | ||
return _interopRequireDefault(_command).default; | ||
} | ||
}); | ||
var _topic = require('./topic'); | ||
Object.defineProperty(exports, 'Topic', { | ||
enumerable: true, | ||
get: function () { | ||
return _interopRequireDefault(_topic).default; | ||
} | ||
}); | ||
var _flags = require('./flags'); | ||
Object.defineProperty(exports, 'flags', { | ||
enumerable: true, | ||
get: function () { | ||
return _flags.flags; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var command_1 = require("./command"); | ||
exports.Command = command_1.Command; | ||
var cli_flags_1 = require("cli-flags"); | ||
exports.flags = cli_flags_1.flags; |
{ | ||
"name": "cli-engine-command", | ||
"description": "base CLI command for cli-engine", | ||
"version": "8.0.15", | ||
"version": "9.0.0-ts.0", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
@@ -12,6 +12,6 @@ "bugs": "https://github.com/heroku/cli-engine-command/issues", | ||
"chalk": "^2.1.0", | ||
"cli-ux": "^1.0.1", | ||
"cli-flags": "^1.0.4", | ||
"cli-ux": "^1.1.1", | ||
"fs-extra": "^4.0.1", | ||
"http-call": "^3.0.2", | ||
"lodash.maxby": "^4.6.0", | ||
"http-call": "ts", | ||
"moment": "^2.18.1", | ||
@@ -22,33 +22,16 @@ "string": "3.x", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "7.2.3", | ||
"babel-jest": "^21.0.2", | ||
"babel-plugin-syntax-object-rest-spread": "^6.13.0", | ||
"babel-plugin-transform-class-properties": "6.24.1", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0", | ||
"babel-plugin-transform-flow-strip-types": "6.22.0", | ||
"cli-engine-config": "^3.2.0", | ||
"eslint": "^4.6.1", | ||
"eslint-config-standard": "10.2.1", | ||
"eslint-plugin-flowtype": "^2.35.1", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-jest": "^21.0.2", | ||
"eslint-plugin-node": "^5.1.0", | ||
"eslint-plugin-promise": "3.5.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"flow-bin": "^0.54.1", | ||
"flow-copy-source": "^1.2.1", | ||
"flow-typed": "^2.1.5", | ||
"@types/chalk": "^0.4.31", | ||
"@types/jest": "^20.0.8", | ||
"@types/nock": "^8.2.1", | ||
"@types/node": "^8.0.28", | ||
"cli-engine-config": "^4.0.1-ts.3", | ||
"del-cli": "^1.1.0", | ||
"husky": "^0.14.3", | ||
"jest": "^21.0.2", | ||
"jest-junit": "^3.0.0", | ||
"lint-staged": "^4.1.3", | ||
"nock": "^9.0.14", | ||
"nodemon": "^1.12.0", | ||
"rimraf": "2.6.1", | ||
"std-mocks": "1.0.1" | ||
"prettier": "^1.6.1", | ||
"ts-jest": "^21.0.0", | ||
"typescript": "^2.5.2" | ||
}, | ||
"engines": { | ||
"node": ">=7.6.0" | ||
}, | ||
"files": [ | ||
@@ -58,9 +41,2 @@ "lib" | ||
"homepage": "https://github.com/heroku/cli-engine-command", | ||
"jest": { | ||
"testEnvironment": "node", | ||
"rootDir": "./src", | ||
"setupFiles": [ | ||
"../test/init.js" | ||
] | ||
}, | ||
"keywords": [ | ||
@@ -71,5 +47,2 @@ "heroku", | ||
"license": "ISC", | ||
"lint-staged": { | ||
"src/**/*.js": "eslint" | ||
}, | ||
"main": "lib/index.js", | ||
@@ -81,10 +54,9 @@ "peerDependencies": { | ||
"scripts": { | ||
"build": "babel src -d lib --ignore '*.test.js'", | ||
"clean": "rimraf lib", | ||
"copy-flow": "flow-copy-source -v -i '**/*.test.js' src lib", | ||
"coverage": "cat coverage/coverage-final.json | remap-istanbul -o coverage/coverage-final.json && curl -s https://codecov.io/bash | bash", | ||
"posttest": "prettier -l 'src/**/*.ts'", | ||
"precommit": "lint-staged", | ||
"prepare": "npm run clean && npm run build && npm run copy-flow", | ||
"test": "jest && flow && eslint .", | ||
"watch": "nodemon -e js -i lib --exec \"npm run prepare\"" | ||
"prepare": "del lib && tsc && del 'lib/**/*.test.js' 'lib/**/*.test.d.ts'", | ||
"pretest": "tsc --sourcemap", | ||
"test": "jest" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
13
340
1
10608
8
245
1
2
+ Addedcli-flags@^1.0.4
+ Added@cli-engine/screen@0.0.0(transitive)
+ Added@heroku-cli/color@1.1.16(transitive)
+ Addedansi-regex@4.1.1(transitive)
+ Addedcli-flags@1.0.19(transitive)
+ Addedcli-ux@2.1.1(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedhttp-call@4.0.0-ts2.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
+ Addedtslib@1.14.1(transitive)
- Removedlodash.maxby@^4.6.0
- Removedhttp-call@3.0.2(transitive)
- Removedlodash.maxby@4.6.0(transitive)
Updatedcli-ux@^1.1.1
Updatedhttp-call@ts