@oclif/plugin-help 3.2.14 → 3.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/help.d.ts +1 -1
- package/lib/commands/help.js +3 -3
- package/lib/index.d.ts +1 -46
- package/lib/index.js +4 -211
- package/oclif.manifest.json +1 -1
- package/package.json +10 -9
- package/lib/_test-help-class.d.ts +0 -6
- package/lib/_test-help-class.js +0 -19
- package/lib/command.d.ts +0 -18
- package/lib/command.js +0 -155
- package/lib/list.d.ts +0 -6
- package/lib/list.js +0 -76
- package/lib/root.d.ts +0 -12
- package/lib/root.js +0 -53
- package/lib/screen.d.ts +0 -2
- package/lib/screen.js +0 -18
- package/lib/util.d.ts +0 -15
- package/lib/util.js +0 -78
package/lib/commands/help.d.ts
CHANGED
package/lib/commands/help.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const command_1 = require("@oclif/command");
|
|
4
|
-
const
|
|
5
|
-
class HelpCommand extends command_1.
|
|
4
|
+
const help_1 = require("@oclif/help");
|
|
5
|
+
class HelpCommand extends command_1.default {
|
|
6
6
|
async run() {
|
|
7
7
|
const { flags, argv } = this.parse(HelpCommand);
|
|
8
|
-
const Help =
|
|
8
|
+
const Help = help_1.getHelpClass(this.config);
|
|
9
9
|
const help = new Help(this.config, { all: flags.all });
|
|
10
10
|
help.showHelp(argv);
|
|
11
11
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,46 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { getHelpClass } from './util';
|
|
3
|
-
export interface HelpOptions {
|
|
4
|
-
all?: boolean;
|
|
5
|
-
maxWidth: number;
|
|
6
|
-
stripAnsi?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare abstract class HelpBase {
|
|
9
|
-
constructor(config: Config.IConfig, opts?: Partial<HelpOptions>);
|
|
10
|
-
protected config: Config.IConfig;
|
|
11
|
-
protected opts: HelpOptions;
|
|
12
|
-
/**
|
|
13
|
-
* Show help, used in multi-command CLIs
|
|
14
|
-
* @param args passed into your command, useful for determining which type of help to display
|
|
15
|
-
*/
|
|
16
|
-
abstract showHelp(argv: string[]): void;
|
|
17
|
-
/**
|
|
18
|
-
* Show help for an individual command
|
|
19
|
-
* @param command
|
|
20
|
-
* @param topics
|
|
21
|
-
*/
|
|
22
|
-
abstract showCommandHelp(command: Config.Command, topics: Config.Topic[]): void;
|
|
23
|
-
}
|
|
24
|
-
export default class Help extends HelpBase {
|
|
25
|
-
render: (input: string) => string;
|
|
26
|
-
private get _topics();
|
|
27
|
-
protected get sortedCommands(): Config.Command.Plugin[];
|
|
28
|
-
protected get sortedTopics(): Config.Topic[];
|
|
29
|
-
constructor(config: Config.IConfig, opts?: Partial<HelpOptions>);
|
|
30
|
-
showHelp(argv: string[]): void;
|
|
31
|
-
showCommandHelp(command: Config.Command): void;
|
|
32
|
-
protected showRootHelp(): void;
|
|
33
|
-
protected showTopicHelp(topic: Config.Topic): void;
|
|
34
|
-
protected formatRoot(): string;
|
|
35
|
-
protected formatCommand(command: Config.Command): string;
|
|
36
|
-
protected formatCommands(commands: Config.Command[]): string;
|
|
37
|
-
protected formatTopic(topic: Config.Topic): string;
|
|
38
|
-
protected formatTopics(topics: Config.Topic[]): string;
|
|
39
|
-
/**
|
|
40
|
-
* @deprecated used for readme generation
|
|
41
|
-
* @param {object} command The command to generate readme help for
|
|
42
|
-
* @return {string} the readme help string for the given command
|
|
43
|
-
*/
|
|
44
|
-
protected command(command: Config.Command): string;
|
|
45
|
-
}
|
|
46
|
-
export { Help, getHelpClass, };
|
|
1
|
+
export { Help, getHelpClass, HelpOptions, HelpBase } from '@oclif/help';
|
package/lib/index.js
CHANGED
|
@@ -1,213 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const command_1 = require("./command");
|
|
8
|
-
const list_1 = require("./list");
|
|
9
|
-
const root_1 = require("./root");
|
|
10
|
-
const screen_1 = require("./screen");
|
|
11
|
-
const util_1 = require("./util");
|
|
12
|
-
const util_2 = require("./util");
|
|
13
|
-
exports.getHelpClass = util_2.getHelpClass;
|
|
14
|
-
const wrap = require('wrap-ansi');
|
|
15
|
-
const { bold, } = chalk;
|
|
16
|
-
const ROOT_INDEX_CMD_ID = '';
|
|
17
|
-
function getHelpSubject(args) {
|
|
18
|
-
for (const arg of args) {
|
|
19
|
-
if (arg === '--')
|
|
20
|
-
return;
|
|
21
|
-
if (arg === 'help' || arg === '--help' || arg === '-h')
|
|
22
|
-
continue;
|
|
23
|
-
if (arg.startsWith('-'))
|
|
24
|
-
return;
|
|
25
|
-
return arg;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
class HelpBase {
|
|
29
|
-
constructor(config, opts = {}) {
|
|
30
|
-
this.config = config;
|
|
31
|
-
this.opts = Object.assign({ maxWidth: screen_1.stdtermwidth }, opts);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.HelpBase = HelpBase;
|
|
35
|
-
class Help extends HelpBase {
|
|
36
|
-
constructor(config, opts = {}) {
|
|
37
|
-
super(config, opts);
|
|
38
|
-
this.render = util_1.template(this);
|
|
39
|
-
}
|
|
40
|
-
/*
|
|
41
|
-
* _topics is to work around Config.topics mistakenly including commands that do
|
|
42
|
-
* not have children, as well as topics. A topic has children, either commands or other topics. When
|
|
43
|
-
* this is fixed upstream config.topics should return *only* topics with children,
|
|
44
|
-
* and this can be removed.
|
|
45
|
-
*/
|
|
46
|
-
get _topics() {
|
|
47
|
-
// since this.config.topics is a getter that does non-trivial work, cache it outside the filter loop for
|
|
48
|
-
// performance benefits in the presence of large numbers of topics
|
|
49
|
-
const topics = this.config.topics;
|
|
50
|
-
return topics.filter((topic) => {
|
|
51
|
-
// it is assumed a topic has a child if it has children
|
|
52
|
-
const hasChild = topics.some(subTopic => subTopic.name.includes(`${topic.name}:`));
|
|
53
|
-
return hasChild;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
get sortedCommands() {
|
|
57
|
-
let commands = this.config.commands;
|
|
58
|
-
commands = commands.filter(c => this.opts.all || !c.hidden);
|
|
59
|
-
commands = util_1.sortBy(commands, c => c.id);
|
|
60
|
-
commands = util_1.uniqBy(commands, c => c.id);
|
|
61
|
-
return commands;
|
|
62
|
-
}
|
|
63
|
-
get sortedTopics() {
|
|
64
|
-
let topics = this._topics;
|
|
65
|
-
topics = topics.filter(t => this.opts.all || !t.hidden);
|
|
66
|
-
topics = util_1.sortBy(topics, t => t.name);
|
|
67
|
-
topics = util_1.uniqBy(topics, t => t.name);
|
|
68
|
-
return topics;
|
|
69
|
-
}
|
|
70
|
-
showHelp(argv) {
|
|
71
|
-
const subject = getHelpSubject(argv);
|
|
72
|
-
if (!subject) {
|
|
73
|
-
const rootCmd = this.config.findCommand(ROOT_INDEX_CMD_ID);
|
|
74
|
-
if (rootCmd)
|
|
75
|
-
this.showCommandHelp(rootCmd);
|
|
76
|
-
this.showRootHelp();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const command = this.config.findCommand(subject);
|
|
80
|
-
if (command) {
|
|
81
|
-
this.showCommandHelp(command);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const topic = this.config.findTopic(subject);
|
|
85
|
-
if (topic) {
|
|
86
|
-
this.showTopicHelp(topic);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
errors_1.error(`command ${subject} not found`);
|
|
90
|
-
}
|
|
91
|
-
showCommandHelp(command) {
|
|
92
|
-
const name = command.id;
|
|
93
|
-
const depth = name.split(':').length;
|
|
94
|
-
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
95
|
-
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
96
|
-
const title = command.description && this.render(command.description).split('\n')[0];
|
|
97
|
-
if (title)
|
|
98
|
-
console.log(title + '\n');
|
|
99
|
-
console.log(this.formatCommand(command));
|
|
100
|
-
console.log('');
|
|
101
|
-
if (subTopics.length > 0) {
|
|
102
|
-
console.log(this.formatTopics(subTopics));
|
|
103
|
-
console.log('');
|
|
104
|
-
}
|
|
105
|
-
if (subCommands.length > 0) {
|
|
106
|
-
console.log(this.formatCommands(subCommands));
|
|
107
|
-
console.log('');
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
showRootHelp() {
|
|
111
|
-
let rootTopics = this.sortedTopics;
|
|
112
|
-
let rootCommands = this.sortedCommands;
|
|
113
|
-
console.log(this.formatRoot());
|
|
114
|
-
console.log('');
|
|
115
|
-
if (!this.opts.all) {
|
|
116
|
-
rootTopics = rootTopics.filter(t => !t.name.includes(':'));
|
|
117
|
-
rootCommands = rootCommands.filter(c => !c.id.includes(':'));
|
|
118
|
-
}
|
|
119
|
-
if (rootTopics.length > 0) {
|
|
120
|
-
console.log(this.formatTopics(rootTopics));
|
|
121
|
-
console.log('');
|
|
122
|
-
}
|
|
123
|
-
if (rootCommands.length > 0) {
|
|
124
|
-
rootCommands = rootCommands.filter(c => c.id);
|
|
125
|
-
console.log(this.formatCommands(rootCommands));
|
|
126
|
-
console.log('');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
showTopicHelp(topic) {
|
|
130
|
-
const name = topic.name;
|
|
131
|
-
const depth = name.split(':').length;
|
|
132
|
-
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
133
|
-
const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
134
|
-
console.log(this.formatTopic(topic));
|
|
135
|
-
if (subTopics.length > 0) {
|
|
136
|
-
console.log(this.formatTopics(subTopics));
|
|
137
|
-
console.log('');
|
|
138
|
-
}
|
|
139
|
-
if (commands.length > 0) {
|
|
140
|
-
console.log(this.formatCommands(commands));
|
|
141
|
-
console.log('');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
formatRoot() {
|
|
145
|
-
const help = new root_1.default(this.config, this.opts);
|
|
146
|
-
return help.root();
|
|
147
|
-
}
|
|
148
|
-
formatCommand(command) {
|
|
149
|
-
const help = new command_1.default(command, this.config, this.opts);
|
|
150
|
-
return help.generate();
|
|
151
|
-
}
|
|
152
|
-
formatCommands(commands) {
|
|
153
|
-
if (commands.length === 0)
|
|
154
|
-
return '';
|
|
155
|
-
const body = list_1.renderList(commands.map(c => [
|
|
156
|
-
c.id,
|
|
157
|
-
c.description && this.render(c.description.split('\n')[0]),
|
|
158
|
-
]), {
|
|
159
|
-
spacer: '\n',
|
|
160
|
-
stripAnsi: this.opts.stripAnsi,
|
|
161
|
-
maxWidth: this.opts.maxWidth - 2,
|
|
162
|
-
});
|
|
163
|
-
return [
|
|
164
|
-
bold('COMMANDS'),
|
|
165
|
-
indent(body, 2),
|
|
166
|
-
].join('\n');
|
|
167
|
-
}
|
|
168
|
-
formatTopic(topic) {
|
|
169
|
-
let description = this.render(topic.description || '');
|
|
170
|
-
const title = description.split('\n')[0];
|
|
171
|
-
description = description.split('\n').slice(1).join('\n');
|
|
172
|
-
let output = util_1.compact([
|
|
173
|
-
title,
|
|
174
|
-
[
|
|
175
|
-
bold('USAGE'),
|
|
176
|
-
indent(wrap(`$ ${this.config.bin} ${topic.name}:COMMAND`, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
177
|
-
].join('\n'),
|
|
178
|
-
description && ([
|
|
179
|
-
bold('DESCRIPTION'),
|
|
180
|
-
indent(wrap(description, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
181
|
-
].join('\n')),
|
|
182
|
-
]).join('\n\n');
|
|
183
|
-
if (this.opts.stripAnsi)
|
|
184
|
-
output = stripAnsi(output);
|
|
185
|
-
return output + '\n';
|
|
186
|
-
}
|
|
187
|
-
formatTopics(topics) {
|
|
188
|
-
if (topics.length === 0)
|
|
189
|
-
return '';
|
|
190
|
-
const body = list_1.renderList(topics.map(c => [
|
|
191
|
-
c.name,
|
|
192
|
-
c.description && this.render(c.description.split('\n')[0]),
|
|
193
|
-
]), {
|
|
194
|
-
spacer: '\n',
|
|
195
|
-
stripAnsi: this.opts.stripAnsi,
|
|
196
|
-
maxWidth: this.opts.maxWidth - 2,
|
|
197
|
-
});
|
|
198
|
-
return [
|
|
199
|
-
bold('TOPICS'),
|
|
200
|
-
indent(body, 2),
|
|
201
|
-
].join('\n');
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* @deprecated used for readme generation
|
|
205
|
-
* @param {object} command The command to generate readme help for
|
|
206
|
-
* @return {string} the readme help string for the given command
|
|
207
|
-
*/
|
|
208
|
-
command(command) {
|
|
209
|
-
return this.formatCommand(command);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
exports.default = Help;
|
|
213
|
-
exports.Help = Help;
|
|
3
|
+
var help_1 = require("@oclif/help");
|
|
4
|
+
exports.Help = help_1.Help;
|
|
5
|
+
exports.getHelpClass = help_1.getHelpClass;
|
|
6
|
+
exports.HelpBase = help_1.HelpBase;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"3.2.
|
|
1
|
+
{"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}]}}}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-help",
|
|
3
3
|
"description": "standard help for oclif",
|
|
4
|
-
"version": "3.2.
|
|
5
|
-
"author": "
|
|
4
|
+
"version": "3.2.18",
|
|
5
|
+
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-help/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@oclif/command": "^1.8.
|
|
9
|
-
"@oclif/config": "
|
|
10
|
-
"@oclif/errors": "
|
|
8
|
+
"@oclif/command": "^1.8.14",
|
|
9
|
+
"@oclif/config": "1.18.2",
|
|
10
|
+
"@oclif/errors": "1.3.5",
|
|
11
|
+
"@oclif/help": "^1.0.0",
|
|
11
12
|
"chalk": "^4.1.2",
|
|
12
13
|
"indent-string": "^4.0.0",
|
|
13
14
|
"lodash": "^4.17.21",
|
|
@@ -17,10 +18,10 @@
|
|
|
17
18
|
"wrap-ansi": "^6.2.0"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"@oclif/dev-cli": "
|
|
21
|
-
"@oclif/plugin-legacy": "
|
|
22
|
-
"@oclif/plugin-plugins": "
|
|
23
|
-
"@oclif/test": "
|
|
21
|
+
"@oclif/dev-cli": "1.26.9",
|
|
22
|
+
"@oclif/plugin-legacy": "1.2.6",
|
|
23
|
+
"@oclif/plugin-plugins": "1.10.10",
|
|
24
|
+
"@oclif/test": "1.2.9",
|
|
24
25
|
"@types/chai": "^4.1.7",
|
|
25
26
|
"@types/lodash": "^4.14.176",
|
|
26
27
|
"@types/mocha": "^8.0.0",
|
package/lib/_test-help-class.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// `getHelpClass` tests require an oclif project for testing so
|
|
3
|
-
// it is re-using the setup here to be able to do a lookup for
|
|
4
|
-
// this sample help class file in tests, although it is not needed
|
|
5
|
-
// for @oclif/plugin-help itself.
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const _1 = require(".");
|
|
8
|
-
class default_1 extends _1.HelpBase {
|
|
9
|
-
showHelp() {
|
|
10
|
-
console.log('help');
|
|
11
|
-
}
|
|
12
|
-
showCommandHelp() {
|
|
13
|
-
console.log('command help');
|
|
14
|
-
}
|
|
15
|
-
getCommandHelpForReadme() {
|
|
16
|
-
return 'help for readme';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.default = default_1;
|
package/lib/command.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as Config from '@oclif/config';
|
|
2
|
-
import { HelpOptions } from '.';
|
|
3
|
-
export default class CommandHelp {
|
|
4
|
-
command: Config.Command;
|
|
5
|
-
config: Config.IConfig;
|
|
6
|
-
opts: HelpOptions;
|
|
7
|
-
render: (input: string) => string;
|
|
8
|
-
constructor(command: Config.Command, config: Config.IConfig, opts: HelpOptions);
|
|
9
|
-
generate(): string;
|
|
10
|
-
protected usage(flags: Config.Command.Flag[]): string;
|
|
11
|
-
protected defaultUsage(_: Config.Command.Flag[]): string;
|
|
12
|
-
protected description(): string | undefined;
|
|
13
|
-
protected aliases(aliases: string[] | undefined): string | undefined;
|
|
14
|
-
protected examples(examples: string[] | undefined | string): string | undefined;
|
|
15
|
-
protected args(args: Config.Command['args']): string | undefined;
|
|
16
|
-
protected arg(arg: Config.Command['args'][0]): string;
|
|
17
|
-
protected flags(flags: Config.Command.Flag[]): string | undefined;
|
|
18
|
-
}
|
package/lib/command.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const indent = require("indent-string");
|
|
5
|
-
const stripAnsi = require("strip-ansi");
|
|
6
|
-
const list_1 = require("./list");
|
|
7
|
-
const util_1 = require("./util");
|
|
8
|
-
const { underline, bold, } = chalk;
|
|
9
|
-
let { dim, } = chalk;
|
|
10
|
-
if (process.env.ConEmuANSI === 'ON') {
|
|
11
|
-
dim = chalk.gray;
|
|
12
|
-
}
|
|
13
|
-
const wrap = require('wrap-ansi');
|
|
14
|
-
class CommandHelp {
|
|
15
|
-
constructor(command, config, opts) {
|
|
16
|
-
this.command = command;
|
|
17
|
-
this.config = config;
|
|
18
|
-
this.opts = opts;
|
|
19
|
-
this.render = util_1.template(this);
|
|
20
|
-
}
|
|
21
|
-
generate() {
|
|
22
|
-
const cmd = this.command;
|
|
23
|
-
const flags = util_1.sortBy(Object.entries(cmd.flags || {})
|
|
24
|
-
.filter(([, v]) => !v.hidden)
|
|
25
|
-
.map(([k, v]) => {
|
|
26
|
-
v.name = k;
|
|
27
|
-
return v;
|
|
28
|
-
}), f => [!f.char, f.char, f.name]);
|
|
29
|
-
const args = (cmd.args || []).filter(a => !a.hidden);
|
|
30
|
-
let output = util_1.compact([
|
|
31
|
-
this.usage(flags),
|
|
32
|
-
this.args(args),
|
|
33
|
-
this.flags(flags),
|
|
34
|
-
this.description(),
|
|
35
|
-
this.aliases(cmd.aliases),
|
|
36
|
-
this.examples(cmd.examples || cmd.example),
|
|
37
|
-
]).join('\n\n');
|
|
38
|
-
if (this.opts.stripAnsi)
|
|
39
|
-
output = stripAnsi(output);
|
|
40
|
-
return output;
|
|
41
|
-
}
|
|
42
|
-
usage(flags) {
|
|
43
|
-
const usage = this.command.usage;
|
|
44
|
-
const body = (usage ? util_1.castArray(usage) : [this.defaultUsage(flags)])
|
|
45
|
-
.map(u => `$ ${this.config.bin} ${u}`.trim())
|
|
46
|
-
.join('\n');
|
|
47
|
-
return [
|
|
48
|
-
bold('USAGE'),
|
|
49
|
-
indent(wrap(this.render(body), this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
50
|
-
].join('\n');
|
|
51
|
-
}
|
|
52
|
-
defaultUsage(_) {
|
|
53
|
-
return util_1.compact([
|
|
54
|
-
this.command.id,
|
|
55
|
-
this.command.args.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
|
|
56
|
-
]).join(' ');
|
|
57
|
-
}
|
|
58
|
-
description() {
|
|
59
|
-
const cmd = this.command;
|
|
60
|
-
const description = cmd.description && this.render(cmd.description).split('\n').slice(1).join('\n');
|
|
61
|
-
if (!description)
|
|
62
|
-
return;
|
|
63
|
-
return [
|
|
64
|
-
bold('DESCRIPTION'),
|
|
65
|
-
indent(wrap(description.trim(), this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
66
|
-
].join('\n');
|
|
67
|
-
}
|
|
68
|
-
aliases(aliases) {
|
|
69
|
-
if (!aliases || aliases.length === 0)
|
|
70
|
-
return;
|
|
71
|
-
const body = aliases.map(a => ['$', this.config.bin, a].join(' ')).join('\n');
|
|
72
|
-
return [
|
|
73
|
-
bold('ALIASES'),
|
|
74
|
-
indent(wrap(body, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
75
|
-
].join('\n');
|
|
76
|
-
}
|
|
77
|
-
examples(examples) {
|
|
78
|
-
if (!examples || examples.length === 0)
|
|
79
|
-
return;
|
|
80
|
-
const body = util_1.castArray(examples).map(a => this.render(a)).join('\n');
|
|
81
|
-
return [
|
|
82
|
-
bold('EXAMPLE' + (examples.length > 1 ? 'S' : '')),
|
|
83
|
-
indent(wrap(body, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
84
|
-
].join('\n');
|
|
85
|
-
}
|
|
86
|
-
args(args) {
|
|
87
|
-
if (args.filter(a => a.description).length === 0)
|
|
88
|
-
return;
|
|
89
|
-
const body = list_1.renderList(args.map(a => {
|
|
90
|
-
var _a;
|
|
91
|
-
const name = a.name.toUpperCase();
|
|
92
|
-
let description = a.description || '';
|
|
93
|
-
// `a.default` is actually not always a string (typing bug), hence `toString()`
|
|
94
|
-
if (a.default || ((_a = a.default) === null || _a === void 0 ? void 0 : _a.toString()) === '0')
|
|
95
|
-
description = `[default: ${a.default}] ${description}`;
|
|
96
|
-
if (a.options)
|
|
97
|
-
description = `(${a.options.join('|')}) ${description}`;
|
|
98
|
-
return [name, description ? dim(description) : undefined];
|
|
99
|
-
}), { stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2 });
|
|
100
|
-
return [
|
|
101
|
-
bold('ARGUMENTS'),
|
|
102
|
-
indent(body, 2),
|
|
103
|
-
].join('\n');
|
|
104
|
-
}
|
|
105
|
-
arg(arg) {
|
|
106
|
-
const name = arg.name.toUpperCase();
|
|
107
|
-
if (arg.required)
|
|
108
|
-
return `${name}`;
|
|
109
|
-
return `[${name}]`;
|
|
110
|
-
}
|
|
111
|
-
flags(flags) {
|
|
112
|
-
if (flags.length === 0)
|
|
113
|
-
return;
|
|
114
|
-
const body = list_1.renderList(flags.map(flag => {
|
|
115
|
-
var _a;
|
|
116
|
-
let left = flag.helpLabel;
|
|
117
|
-
if (!left) {
|
|
118
|
-
const label = [];
|
|
119
|
-
if (flag.char)
|
|
120
|
-
label.push(`-${flag.char[0]}`);
|
|
121
|
-
if (flag.name) {
|
|
122
|
-
if (flag.type === 'boolean' && flag.allowNo) {
|
|
123
|
-
label.push(`--[no-]${flag.name.trim()}`);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
label.push(`--${flag.name.trim()}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
left = label.join(', ');
|
|
130
|
-
}
|
|
131
|
-
if (flag.type === 'option') {
|
|
132
|
-
let value = flag.helpValue || flag.name;
|
|
133
|
-
if (!flag.helpValue && flag.options) {
|
|
134
|
-
value = flag.options.join('|');
|
|
135
|
-
}
|
|
136
|
-
if (!value.includes('|'))
|
|
137
|
-
value = underline(value);
|
|
138
|
-
left += `=${value}`;
|
|
139
|
-
}
|
|
140
|
-
let right = flag.description || '';
|
|
141
|
-
// `flag.default` is not always a string (typing bug), hence `toString()`
|
|
142
|
-
if (flag.type === 'option' && (flag.default || ((_a = flag.default) === null || _a === void 0 ? void 0 : _a.toString()) === '0')) {
|
|
143
|
-
right = `[default: ${flag.default}] ${right}`;
|
|
144
|
-
}
|
|
145
|
-
if (flag.required)
|
|
146
|
-
right = `(required) ${right}`;
|
|
147
|
-
return [left, dim(right.trim())];
|
|
148
|
-
}), { stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2 });
|
|
149
|
-
return [
|
|
150
|
-
bold('OPTIONS'),
|
|
151
|
-
indent(body, 2),
|
|
152
|
-
].join('\n');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.default = CommandHelp;
|
package/lib/list.d.ts
DELETED
package/lib/list.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const indent = require("indent-string");
|
|
4
|
-
const stripAnsi = require("strip-ansi");
|
|
5
|
-
const width = require('string-width');
|
|
6
|
-
const wrap = require('wrap-ansi');
|
|
7
|
-
const widestLine = require('widest-line');
|
|
8
|
-
function renderList(input, opts) {
|
|
9
|
-
if (input.length === 0) {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
const renderMultiline = () => {
|
|
13
|
-
let output = '';
|
|
14
|
-
for (let [left, right] of input) {
|
|
15
|
-
if (!left && !right)
|
|
16
|
-
continue;
|
|
17
|
-
if (left) {
|
|
18
|
-
if (opts.stripAnsi)
|
|
19
|
-
left = stripAnsi(left);
|
|
20
|
-
output += wrap(left.trim(), opts.maxWidth, { hard: true, trim: true });
|
|
21
|
-
}
|
|
22
|
-
if (right) {
|
|
23
|
-
if (opts.stripAnsi)
|
|
24
|
-
right = stripAnsi(right);
|
|
25
|
-
output += '\n';
|
|
26
|
-
output += indent(wrap(right.trim(), opts.maxWidth - 2, { hard: true, trim: true }), 4);
|
|
27
|
-
}
|
|
28
|
-
output += '\n\n';
|
|
29
|
-
}
|
|
30
|
-
return output.trim();
|
|
31
|
-
};
|
|
32
|
-
if (opts.multiline)
|
|
33
|
-
return renderMultiline();
|
|
34
|
-
const maxLength = widestLine(input.map(i => i[0]).join('\n'));
|
|
35
|
-
let output = '';
|
|
36
|
-
let spacer = opts.spacer || '\n';
|
|
37
|
-
let cur = '';
|
|
38
|
-
for (const [left, r] of input) {
|
|
39
|
-
let right = r;
|
|
40
|
-
if (cur) {
|
|
41
|
-
output += spacer;
|
|
42
|
-
output += cur;
|
|
43
|
-
}
|
|
44
|
-
cur = left || '';
|
|
45
|
-
if (opts.stripAnsi)
|
|
46
|
-
cur = stripAnsi(cur);
|
|
47
|
-
if (!right) {
|
|
48
|
-
cur = cur.trim();
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (opts.stripAnsi)
|
|
52
|
-
right = stripAnsi(right);
|
|
53
|
-
right = wrap(right.trim(), opts.maxWidth - (maxLength + 2), { hard: true, trim: true });
|
|
54
|
-
// right = wrap(right.trim(), screen.stdtermwidth - (maxLength + 4), {hard: true, trim: false})
|
|
55
|
-
const [first, ...lines] = right.split('\n').map(s => s.trim());
|
|
56
|
-
cur += ' '.repeat(maxLength - width(cur) + 2);
|
|
57
|
-
cur += first;
|
|
58
|
-
if (lines.length === 0) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
// if we start putting too many lines down, render in multiline format
|
|
62
|
-
if (lines.length > 4)
|
|
63
|
-
return renderMultiline();
|
|
64
|
-
// if spacer is not defined, separate all rows with extra newline
|
|
65
|
-
if (!opts.spacer)
|
|
66
|
-
spacer = '\n\n';
|
|
67
|
-
cur += '\n';
|
|
68
|
-
cur += indent(lines.join('\n'), maxLength + 2);
|
|
69
|
-
}
|
|
70
|
-
if (cur) {
|
|
71
|
-
output += spacer;
|
|
72
|
-
output += cur;
|
|
73
|
-
}
|
|
74
|
-
return output.trim();
|
|
75
|
-
}
|
|
76
|
-
exports.renderList = renderList;
|
package/lib/root.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as Config from '@oclif/config';
|
|
2
|
-
import { HelpOptions } from '.';
|
|
3
|
-
export default class RootHelp {
|
|
4
|
-
config: Config.IConfig;
|
|
5
|
-
opts: HelpOptions;
|
|
6
|
-
render: (input: string) => string;
|
|
7
|
-
constructor(config: Config.IConfig, opts: HelpOptions);
|
|
8
|
-
root(): string;
|
|
9
|
-
protected usage(): string;
|
|
10
|
-
protected description(): string | undefined;
|
|
11
|
-
protected version(): string;
|
|
12
|
-
}
|
package/lib/root.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const indent = require("indent-string");
|
|
5
|
-
const stripAnsi = require("strip-ansi");
|
|
6
|
-
const util_1 = require("./util");
|
|
7
|
-
const wrap = require('wrap-ansi');
|
|
8
|
-
const { bold, } = chalk;
|
|
9
|
-
class RootHelp {
|
|
10
|
-
constructor(config, opts) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.opts = opts;
|
|
13
|
-
this.render = util_1.template(this);
|
|
14
|
-
}
|
|
15
|
-
root() {
|
|
16
|
-
let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
|
|
17
|
-
description = this.render(description);
|
|
18
|
-
description = description.split('\n')[0];
|
|
19
|
-
let output = util_1.compact([
|
|
20
|
-
description,
|
|
21
|
-
this.version(),
|
|
22
|
-
this.usage(),
|
|
23
|
-
this.description(),
|
|
24
|
-
]).join('\n\n');
|
|
25
|
-
if (this.opts.stripAnsi)
|
|
26
|
-
output = stripAnsi(output);
|
|
27
|
-
return output;
|
|
28
|
-
}
|
|
29
|
-
usage() {
|
|
30
|
-
return [
|
|
31
|
-
bold('USAGE'),
|
|
32
|
-
indent(wrap(`$ ${this.config.bin} [COMMAND]`, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
33
|
-
].join('\n');
|
|
34
|
-
}
|
|
35
|
-
description() {
|
|
36
|
-
let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
|
|
37
|
-
description = this.render(description);
|
|
38
|
-
description = description.split('\n').slice(1).join('\n');
|
|
39
|
-
if (!description)
|
|
40
|
-
return;
|
|
41
|
-
return [
|
|
42
|
-
bold('DESCRIPTION'),
|
|
43
|
-
indent(wrap(description, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
44
|
-
].join('\n');
|
|
45
|
-
}
|
|
46
|
-
version() {
|
|
47
|
-
return [
|
|
48
|
-
bold('VERSION'),
|
|
49
|
-
indent(wrap(this.config.userAgent, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
50
|
-
].join('\n');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.default = RootHelp;
|
package/lib/screen.d.ts
DELETED
package/lib/screen.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function termwidth(stream) {
|
|
4
|
-
if (!stream.isTTY) {
|
|
5
|
-
return 80;
|
|
6
|
-
}
|
|
7
|
-
const width = stream.getWindowSize()[0];
|
|
8
|
-
if (width < 1) {
|
|
9
|
-
return 80;
|
|
10
|
-
}
|
|
11
|
-
if (width < 40) {
|
|
12
|
-
return 40;
|
|
13
|
-
}
|
|
14
|
-
return width;
|
|
15
|
-
}
|
|
16
|
-
const columns = parseInt(process.env.COLUMNS, 10) || global.columns;
|
|
17
|
-
exports.stdtermwidth = columns || termwidth(process.stdout);
|
|
18
|
-
exports.errtermwidth = columns || termwidth(process.stderr);
|
package/lib/util.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { IConfig } from '@oclif/config';
|
|
2
|
-
import { HelpBase, HelpOptions } from '.';
|
|
3
|
-
export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
|
|
4
|
-
export declare function compact<T>(a: (T | undefined)[]): T[];
|
|
5
|
-
export declare function castArray<T>(input?: T | T[]): T[];
|
|
6
|
-
export declare function sortBy<T>(arr: T[], fn: (i: T) => sort.Types | sort.Types[]): T[];
|
|
7
|
-
export declare namespace sort {
|
|
8
|
-
type Types = string | number | undefined | boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function template(context: any): (t: string) => string;
|
|
11
|
-
interface HelpBaseDerived {
|
|
12
|
-
new (config: IConfig, opts?: Partial<HelpOptions>): HelpBase;
|
|
13
|
-
}
|
|
14
|
-
export declare function getHelpClass(config: IConfig, defaultClass?: string): HelpBaseDerived;
|
|
15
|
-
export {};
|
package/lib/util.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ts_node_1 = require("@oclif/config/lib/ts-node");
|
|
4
|
-
const _ = require("lodash");
|
|
5
|
-
function uniqBy(arr, fn) {
|
|
6
|
-
return arr.filter((a, i) => {
|
|
7
|
-
const aVal = fn(a);
|
|
8
|
-
return !arr.find((b, j) => j > i && fn(b) === aVal);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
exports.uniqBy = uniqBy;
|
|
12
|
-
function compact(a) {
|
|
13
|
-
return a.filter((a) => Boolean(a));
|
|
14
|
-
}
|
|
15
|
-
exports.compact = compact;
|
|
16
|
-
function castArray(input) {
|
|
17
|
-
if (input === undefined)
|
|
18
|
-
return [];
|
|
19
|
-
return Array.isArray(input) ? input : [input];
|
|
20
|
-
}
|
|
21
|
-
exports.castArray = castArray;
|
|
22
|
-
function sortBy(arr, fn) {
|
|
23
|
-
function compare(a, b) {
|
|
24
|
-
a = a === undefined ? 0 : a;
|
|
25
|
-
b = b === undefined ? 0 : b;
|
|
26
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
27
|
-
if (a.length === 0 && b.length === 0)
|
|
28
|
-
return 0;
|
|
29
|
-
const diff = compare(a[0], b[0]);
|
|
30
|
-
if (diff !== 0)
|
|
31
|
-
return diff;
|
|
32
|
-
return compare(a.slice(1), b.slice(1));
|
|
33
|
-
}
|
|
34
|
-
if (a < b)
|
|
35
|
-
return -1;
|
|
36
|
-
if (a > b)
|
|
37
|
-
return 1;
|
|
38
|
-
return 0;
|
|
39
|
-
}
|
|
40
|
-
return arr.sort((a, b) => compare(fn(a), fn(b)));
|
|
41
|
-
}
|
|
42
|
-
exports.sortBy = sortBy;
|
|
43
|
-
function template(context) {
|
|
44
|
-
function render(t) {
|
|
45
|
-
return _.template(t)(context);
|
|
46
|
-
}
|
|
47
|
-
return render;
|
|
48
|
-
}
|
|
49
|
-
exports.template = template;
|
|
50
|
-
function extractExport(config, classPath) {
|
|
51
|
-
const helpClassPath = ts_node_1.tsPath(config.root, classPath);
|
|
52
|
-
return require(helpClassPath);
|
|
53
|
-
}
|
|
54
|
-
function extractClass(exported) {
|
|
55
|
-
return exported && exported.default ? exported.default : exported;
|
|
56
|
-
}
|
|
57
|
-
function getHelpClass(config, defaultClass = '@oclif/plugin-help') {
|
|
58
|
-
const pjson = config.pjson;
|
|
59
|
-
const configuredClass = pjson && pjson.oclif && pjson.oclif.helpClass;
|
|
60
|
-
if (configuredClass) {
|
|
61
|
-
try {
|
|
62
|
-
const exported = extractExport(config, configuredClass);
|
|
63
|
-
return extractClass(exported);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
throw new Error(`Unable to load configured help class "${configuredClass}", failed with message:\n${error.message}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
const defaultModulePath = require.resolve(defaultClass, { paths: [config.root] });
|
|
71
|
-
const exported = require(defaultModulePath);
|
|
72
|
-
return extractClass(exported);
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
throw new Error(`Could not load a help class, consider installing the @oclif/plugin-help package, failed with message:\n${error.message}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.getHelpClass = getHelpClass;
|