Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-engine-command

Package Overview
Dependencies
Maintainers
3
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-engine-command - npm Package Compare versions

Comparing version 3.0.2 to 3.0.3

78

lib/topic.js

@@ -6,5 +6,2 @@ 'use strict';

});
var _screen = require('./output/screen');
class Topic {

@@ -16,79 +13,4 @@ constructor(commands, out) {

async help(args, matchedCommand) {
if (matchedCommand) this.commandHelp(matchedCommand);
if (args.slice(0, 2).includes(this.constructor.topic)) this.listCommandsHelp();
}
listCommandsHelp() {
let commands = this.commands.filter(c => !c.hidden).map(c => [this.usage(c), c.description]);
if (commands.length === 0) return;
this.out.log(`${this.out.config.bin} ${this.constructor.topic} commands: (${this.out.color.cmd(this.out.config.bin + ' help ' + this.constructor.topic + ':COMMAND')} for details)\n`);
this.out.log(this.renderList(commands));
this.out.log();
}
commandHelp(command) {
let usage = `${this.out.config.bin} ${this.usage(command)}`;
this.out.log(`Usage: ${this.out.color.cmd(usage)}\n`);
if (command.description) this.out.log(`${command.description.trim()}\n`);
let flags = Object.keys(command.flags || {}).map(f => [f, command.flags[f]]).filter(f => !f[1].hidden);
if (flags.length) this.out.log(`${this.renderFlags(flags)}\n`);
if (command.help) this.out.log(`${command.help.trim()}\n`);
}
renderArg(arg) {
let name = arg.name.toUpperCase();
if (arg.required !== false && arg.optional !== true) return `${name}`;else return `[${name}]`;
}
renderFlags(flags) {
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 this.renderList(flags.map(([name, f]) => {
let label = [];
if (f.char) label.push(`-${f.char}`);
if (name) label.push(` --${name}`);
let usage = f.hasValue ? ` ${name.toUpperCase()}` : '';
let description = f.description || '';
if (f.required || f.optional === false) description = `(required) ${description}`;
return [label.join(',').trim() + usage, description];
}));
}
usage(command) {
if (command.usage) return command.usage.trim();
let cmd = command.command ? `${command.topic}:${command.command}` : command.topic;
if (!command.args) return cmd.trim();
let args = command.args.map(this.renderArg);
return `${cmd} ${args.join(' ')}`.trim();
}
renderList(items) {
const S = require('string');
const max = require('lodash.maxby');
let maxLength = max(items, '[0].length')[0].length + 1;
let lines = items.map(i => {
let left = ` ${i[0]}`;
let right = i[1];
if (!right) return left;
left = `${S(left).padRight(maxLength)}`;
right = this.linewrap(maxLength + 4, right);
return `${left} # ${right}`;
});
return lines.join('\n');
}
linewrap(length, s) {
const linewrap = require('./output/linewrap');
return linewrap(length, _screen.stdtermwidth, {
skipScheme: 'ansi-color'
})(s).trim();
}
}
exports.default = Topic;
Topic.hidden = false;

4

package.json
{
"name": "cli-engine-command",
"description": "base CLI command for cli-engine",
"version": "3.0.2",
"version": "3.0.3",
"author": "Jeff Dickey @dickeyxxx",

@@ -14,3 +14,3 @@ "bugs": "https://github.com/heroku/cli-engine-command/issues",

"got": "^6.7.1",
"http-call": "^1.1.0",
"http-call": "^1.1.1",
"jest-validate": "^19.0.2",

@@ -17,0 +17,0 @@ "lodash.maxby": "^4.6.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc