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

@oclif/plugin-help

Package Overview
Dependencies
Maintainers
7
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oclif/plugin-help - npm Package Compare versions

Comparing version 3.2.17 to 3.2.18

3

lib/commands/help.d.ts

@@ -1,3 +0,2 @@

import Command from '@oclif/cmd/lib/command';
import * as flags from '@oclif/cmd/lib/flags';
import Command, { flags } from '@oclif/command';
export default class HelpCommand extends Command {

@@ -4,0 +3,0 @@ static description: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/cmd/lib/command");
const flags = require("@oclif/cmd/lib/flags");
const __1 = require("..");
const command_1 = require("@oclif/command");
const help_1 = require("@oclif/help");
class HelpCommand extends command_1.default {
async run() {
const { flags, argv } = this.parse(HelpCommand);
const Help = __1.getHelpClass(this.config);
const Help = help_1.getHelpClass(this.config);
const help = new Help(this.config, { all: flags.all });

@@ -17,3 +16,3 @@ help.showHelp(argv);

HelpCommand.flags = {
all: flags.boolean({ description: 'see all commands in CLI' }),
all: command_1.flags.boolean({ description: 'see all commands in CLI' }),
};

@@ -20,0 +19,0 @@ HelpCommand.args = [

@@ -1,46 +0,1 @@

import * as Config from '@oclif/config';
import { getHelpClass } from './util';
export interface HelpOptions {
all?: boolean;
maxWidth: number;
stripAnsi?: boolean;
}
export declare abstract class HelpBase {
constructor(config: Config.IConfig, opts?: Partial<HelpOptions>);
protected config: Config.IConfig;
protected opts: HelpOptions;
/**
* Show help, used in multi-command CLIs
* @param args passed into your command, useful for determining which type of help to display
*/
abstract showHelp(argv: string[]): void;
/**
* Show help for an individual command
* @param command
* @param topics
*/
abstract showCommandHelp(command: Config.Command, topics: Config.Topic[]): void;
}
export default class Help extends HelpBase {
render: (input: string) => string;
private get _topics();
protected get sortedCommands(): Config.Command.Plugin[];
protected get sortedTopics(): Config.Topic[];
constructor(config: Config.IConfig, opts?: Partial<HelpOptions>);
showHelp(argv: string[]): void;
showCommandHelp(command: Config.Command): void;
protected showRootHelp(): void;
protected showTopicHelp(topic: Config.Topic): void;
protected formatRoot(): string;
protected formatCommand(command: Config.Command): string;
protected formatCommands(commands: Config.Command[]): string;
protected formatTopic(topic: Config.Topic): string;
protected formatTopics(topics: Config.Topic[]): string;
/**
* @deprecated used for readme generation
* @param {object} command The command to generate readme help for
* @return {string} the readme help string for the given command
*/
protected command(command: Config.Command): string;
}
export { Help, getHelpClass, };
export { Help, getHelpClass, HelpOptions, HelpBase } from '@oclif/help';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@oclif/errors");
const chalk = require("chalk");
const indent = require("indent-string");
const stripAnsi = require("strip-ansi");
const command_1 = require("./command");
const list_1 = require("./list");
const root_1 = require("./root");
const screen_1 = require("./screen");
const util_1 = require("./util");
const util_2 = require("./util");
exports.getHelpClass = util_2.getHelpClass;
const wrap = require('wrap-ansi');
const { bold, } = chalk;
const ROOT_INDEX_CMD_ID = '';
function getHelpSubject(args) {
for (const arg of args) {
if (arg === '--')
return;
if (arg === 'help' || arg === '--help' || arg === '-h')
continue;
if (arg.startsWith('-'))
return;
return arg;
}
}
class HelpBase {
constructor(config, opts = {}) {
this.config = config;
this.opts = Object.assign({ maxWidth: screen_1.stdtermwidth }, opts);
}
}
exports.HelpBase = HelpBase;
class Help extends HelpBase {
constructor(config, opts = {}) {
super(config, opts);
this.render = util_1.template(this);
}
/*
* _topics is to work around Config.topics mistakenly including commands that do
* not have children, as well as topics. A topic has children, either commands or other topics. When
* this is fixed upstream config.topics should return *only* topics with children,
* and this can be removed.
*/
get _topics() {
// since this.config.topics is a getter that does non-trivial work, cache it outside the filter loop for
// performance benefits in the presence of large numbers of topics
const topics = this.config.topics;
return topics.filter((topic) => {
// it is assumed a topic has a child if it has children
const hasChild = topics.some(subTopic => subTopic.name.includes(`${topic.name}:`));
return hasChild;
});
}
get sortedCommands() {
let commands = this.config.commands;
commands = commands.filter(c => this.opts.all || !c.hidden);
commands = util_1.sortBy(commands, c => c.id);
commands = util_1.uniqBy(commands, c => c.id);
return commands;
}
get sortedTopics() {
let topics = this._topics;
topics = topics.filter(t => this.opts.all || !t.hidden);
topics = util_1.sortBy(topics, t => t.name);
topics = util_1.uniqBy(topics, t => t.name);
return topics;
}
showHelp(argv) {
const subject = getHelpSubject(argv);
if (!subject) {
const rootCmd = this.config.findCommand(ROOT_INDEX_CMD_ID);
if (rootCmd)
this.showCommandHelp(rootCmd);
this.showRootHelp();
return;
}
const command = this.config.findCommand(subject);
if (command) {
this.showCommandHelp(command);
return;
}
const topic = this.config.findTopic(subject);
if (topic) {
this.showTopicHelp(topic);
return;
}
errors_1.error(`command ${subject} not found`);
}
showCommandHelp(command) {
const name = command.id;
const depth = name.split(':').length;
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
const title = command.description && this.render(command.description).split('\n')[0];
if (title)
console.log(title + '\n');
console.log(this.formatCommand(command));
console.log('');
if (subTopics.length > 0) {
console.log(this.formatTopics(subTopics));
console.log('');
}
if (subCommands.length > 0) {
console.log(this.formatCommands(subCommands));
console.log('');
}
}
showRootHelp() {
let rootTopics = this.sortedTopics;
let rootCommands = this.sortedCommands;
console.log(this.formatRoot());
console.log('');
if (!this.opts.all) {
rootTopics = rootTopics.filter(t => !t.name.includes(':'));
rootCommands = rootCommands.filter(c => !c.id.includes(':'));
}
if (rootTopics.length > 0) {
console.log(this.formatTopics(rootTopics));
console.log('');
}
if (rootCommands.length > 0) {
rootCommands = rootCommands.filter(c => c.id);
console.log(this.formatCommands(rootCommands));
console.log('');
}
}
showTopicHelp(topic) {
const name = topic.name;
const depth = name.split(':').length;
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
console.log(this.formatTopic(topic));
if (subTopics.length > 0) {
console.log(this.formatTopics(subTopics));
console.log('');
}
if (commands.length > 0) {
console.log(this.formatCommands(commands));
console.log('');
}
}
formatRoot() {
const help = new root_1.default(this.config, this.opts);
return help.root();
}
formatCommand(command) {
const help = new command_1.default(command, this.config, this.opts);
return help.generate();
}
formatCommands(commands) {
if (commands.length === 0)
return '';
const body = list_1.renderList(commands.map(c => [
c.id,
c.description && this.render(c.description.split('\n')[0]),
]), {
spacer: '\n',
stripAnsi: this.opts.stripAnsi,
maxWidth: this.opts.maxWidth - 2,
});
return [
bold('COMMANDS'),
indent(body, 2),
].join('\n');
}
formatTopic(topic) {
let description = this.render(topic.description || '');
const title = description.split('\n')[0];
description = description.split('\n').slice(1).join('\n');
let output = util_1.compact([
title,
[
bold('USAGE'),
indent(wrap(`$ ${this.config.bin} ${topic.name}:COMMAND`, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
].join('\n'),
description && ([
bold('DESCRIPTION'),
indent(wrap(description, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
].join('\n')),
]).join('\n\n');
if (this.opts.stripAnsi)
output = stripAnsi(output);
return output + '\n';
}
formatTopics(topics) {
if (topics.length === 0)
return '';
const body = list_1.renderList(topics.map(c => [
c.name,
c.description && this.render(c.description.split('\n')[0]),
]), {
spacer: '\n',
stripAnsi: this.opts.stripAnsi,
maxWidth: this.opts.maxWidth - 2,
});
return [
bold('TOPICS'),
indent(body, 2),
].join('\n');
}
/**
* @deprecated used for readme generation
* @param {object} command The command to generate readme help for
* @return {string} the readme help string for the given command
*/
command(command) {
return this.formatCommand(command);
}
}
exports.default = Help;
exports.Help = Help;
var help_1 = require("@oclif/help");
exports.Help = help_1.Help;
exports.getHelpClass = help_1.getHelpClass;
exports.HelpBase = help_1.HelpBase;

@@ -1,1 +0,1 @@

{"version":"3.2.17","commands":{"help":{"id":"help","description":"display help for <%= config.bin %>","pluginName":"@oclif/plugin-help","pluginType":"core","aliases":[],"flags":{"all":{"name":"all","type":"boolean","description":"see all commands in CLI","allowNo":false}},"args":[{"name":"command","description":"command to show help for","required":false}]}}}
{"version":"3.2.18","commands":{"help":{"id":"help","description":"display help for <%= config.bin %>","pluginName":"@oclif/plugin-help","pluginType":"core","aliases":[],"flags":{"all":{"name":"all","type":"boolean","description":"see all commands in CLI","allowNo":false}},"args":[{"name":"command","description":"command to show help for","required":false}]}}}
{
"name": "@oclif/plugin-help",
"description": "standard help for oclif",
"version": "3.2.17",
"author": "Jeff Dickey @jdxcode",
"version": "3.2.18",
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-help/issues",
"dependencies": {
"@oclif/cmd": "npm:@oclif/command@1.8.12",
"@oclif/command": "^1.8.14",
"@oclif/config": "1.18.2",
"@oclif/errors": "1.3.5",
"@oclif/help": "^1.0.0",
"chalk": "^4.1.2",

@@ -12,0 +13,0 @@ "indent-string": "^4.0.0",

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