@oclif/plugin-help 2.1.3 → 2.2.1
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/CHANGELOG.md +7 -0
- package/lib/command.d.ts +6 -5
- package/lib/command.js +28 -21
- package/lib/index.d.ts +1 -0
- package/lib/index.js +17 -14
- package/oclif.manifest.json +1 -1
- package/package.json +16 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.1.4](https://github.com/oclif/plugin-help/compare/v2.1.3...v2.1.4) (2018-11-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Expose command help method ([#33](https://github.com/oclif/plugin-help/issues/33)) ([0c0a0d9](https://github.com/oclif/plugin-help/commit/0c0a0d9))
|
|
7
|
+
|
|
1
8
|
## [2.1.3](https://github.com/oclif/plugin-help/compare/v2.1.2...v2.1.3) (2018-10-13)
|
|
2
9
|
|
|
3
10
|
|
package/lib/command.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as Config from '@oclif/config';
|
|
2
2
|
import { HelpOptions } from '.';
|
|
3
3
|
export default class CommandHelp {
|
|
4
|
+
command: Config.Command;
|
|
4
5
|
config: Config.IConfig;
|
|
5
6
|
opts: HelpOptions;
|
|
6
7
|
render: (input: string) => string;
|
|
7
|
-
constructor(config: Config.IConfig, opts: HelpOptions);
|
|
8
|
-
|
|
9
|
-
protected usage(
|
|
10
|
-
protected defaultUsage(
|
|
11
|
-
protected description(
|
|
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;
|
|
12
13
|
protected aliases(aliases: string[] | undefined): string | undefined;
|
|
13
14
|
protected examples(examples: string[] | undefined | string): string | undefined;
|
|
14
15
|
protected args(args: Config.Command['args']): string | undefined;
|
package/lib/command.js
CHANGED
|
@@ -11,12 +11,14 @@ if (process.env.ConEmuANSI === 'ON') {
|
|
|
11
11
|
}
|
|
12
12
|
const wrap = require('wrap-ansi');
|
|
13
13
|
class CommandHelp {
|
|
14
|
-
constructor(config, opts) {
|
|
14
|
+
constructor(command, config, opts) {
|
|
15
|
+
this.command = command;
|
|
15
16
|
this.config = config;
|
|
16
17
|
this.opts = opts;
|
|
17
18
|
this.render = util_1.template(this);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
generate() {
|
|
21
|
+
const cmd = this.command;
|
|
20
22
|
const flags = util_1.sortBy(Object.entries(cmd.flags || {})
|
|
21
23
|
.filter(([, v]) => !v.hidden)
|
|
22
24
|
.map(([k, v]) => {
|
|
@@ -25,10 +27,10 @@ class CommandHelp {
|
|
|
25
27
|
}), f => [!f.char, f.char, f.name]);
|
|
26
28
|
const args = (cmd.args || []).filter(a => !a.hidden);
|
|
27
29
|
let output = util_1.compact([
|
|
28
|
-
this.usage(
|
|
30
|
+
this.usage(flags),
|
|
29
31
|
this.args(args),
|
|
30
32
|
this.flags(flags),
|
|
31
|
-
this.description(
|
|
33
|
+
this.description(),
|
|
32
34
|
this.aliases(cmd.aliases),
|
|
33
35
|
this.examples(cmd.examples || cmd.example),
|
|
34
36
|
]).join('\n\n');
|
|
@@ -36,22 +38,24 @@ class CommandHelp {
|
|
|
36
38
|
output = stripAnsi(output);
|
|
37
39
|
return output;
|
|
38
40
|
}
|
|
39
|
-
usage(
|
|
40
|
-
|
|
41
|
+
usage(flags) {
|
|
42
|
+
const usage = this.command.usage;
|
|
43
|
+
let body = (usage ? util_1.castArray(usage) : [this.defaultUsage(flags)])
|
|
41
44
|
.map(u => `$ ${this.config.bin} ${u}`.trim())
|
|
42
45
|
.join('\n');
|
|
43
46
|
return [
|
|
44
47
|
bold('USAGE'),
|
|
45
|
-
indent(wrap(body, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
48
|
+
indent(wrap(this.render(body), this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
|
46
49
|
].join('\n');
|
|
47
50
|
}
|
|
48
|
-
defaultUsage(
|
|
51
|
+
defaultUsage(_) {
|
|
49
52
|
return util_1.compact([
|
|
50
|
-
command.id,
|
|
51
|
-
command.args.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
|
|
53
|
+
this.command.id,
|
|
54
|
+
this.command.args.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
|
|
52
55
|
]).join(' ');
|
|
53
56
|
}
|
|
54
|
-
description(
|
|
57
|
+
description() {
|
|
58
|
+
const cmd = this.command;
|
|
55
59
|
let description = cmd.description && this.render(cmd.description).split('\n').slice(1).join('\n');
|
|
56
60
|
if (!description)
|
|
57
61
|
return;
|
|
@@ -105,18 +109,21 @@ class CommandHelp {
|
|
|
105
109
|
if (!flags.length)
|
|
106
110
|
return;
|
|
107
111
|
let body = list_1.renderList(flags.map(flag => {
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
label
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
let left = flag.helpLabel;
|
|
113
|
+
if (!left) {
|
|
114
|
+
const label = [];
|
|
115
|
+
if (flag.char)
|
|
116
|
+
label.push(`-${flag.char[0]}`);
|
|
117
|
+
if (flag.name) {
|
|
118
|
+
if (flag.type === 'boolean' && flag.allowNo) {
|
|
119
|
+
label.push(`--[no-]${flag.name.trim()}`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
label.push(`--${flag.name.trim()}`);
|
|
123
|
+
}
|
|
117
124
|
}
|
|
125
|
+
left = label.join(', ');
|
|
118
126
|
}
|
|
119
|
-
let left = label.join(', ');
|
|
120
127
|
if (flag.type === 'option') {
|
|
121
128
|
let value = flag.helpValue || flag.name;
|
|
122
129
|
if (!flag.helpValue && flag.options) {
|
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export default class Help {
|
|
|
10
10
|
render: (input: string) => string;
|
|
11
11
|
constructor(config: Config.IConfig, opts?: Partial<HelpOptions>);
|
|
12
12
|
showHelp(argv: string[]): void;
|
|
13
|
+
showCommandHelp(command: Config.Command, topics: Config.Topic[]): void;
|
|
13
14
|
root(): string;
|
|
14
15
|
topic(topic: Config.Topic): string;
|
|
15
16
|
command(command: Config.Command): string;
|
package/lib/index.js
CHANGED
|
@@ -49,18 +49,7 @@ class Help {
|
|
|
49
49
|
console.log();
|
|
50
50
|
}
|
|
51
51
|
else if (command = this.config.findCommand(subject)) {
|
|
52
|
-
|
|
53
|
-
const depth = name.split(':').length;
|
|
54
|
-
topics = topics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
55
|
-
let title = command.description && this.render(command.description).split('\n')[0];
|
|
56
|
-
if (title)
|
|
57
|
-
console.log(title + '\n');
|
|
58
|
-
console.log(this.command(command));
|
|
59
|
-
console.log();
|
|
60
|
-
if (topics.length) {
|
|
61
|
-
console.log(this.topics(topics));
|
|
62
|
-
console.log();
|
|
63
|
-
}
|
|
52
|
+
this.showCommandHelp(command, topics);
|
|
64
53
|
}
|
|
65
54
|
else if (topic = this.config.findTopic(subject)) {
|
|
66
55
|
const name = topic.name;
|
|
@@ -76,6 +65,20 @@ class Help {
|
|
|
76
65
|
errors_1.error(`command ${subject} not found`);
|
|
77
66
|
}
|
|
78
67
|
}
|
|
68
|
+
showCommandHelp(command, topics) {
|
|
69
|
+
const name = command.id;
|
|
70
|
+
const depth = name.split(':').length;
|
|
71
|
+
topics = topics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
72
|
+
let title = command.description && this.render(command.description).split('\n')[0];
|
|
73
|
+
if (title)
|
|
74
|
+
console.log(title + '\n');
|
|
75
|
+
console.log(this.command(command));
|
|
76
|
+
console.log();
|
|
77
|
+
if (topics.length) {
|
|
78
|
+
console.log(this.topics(topics));
|
|
79
|
+
console.log();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
79
82
|
root() {
|
|
80
83
|
const help = new root_1.default(this.config, this.opts);
|
|
81
84
|
return help.root();
|
|
@@ -100,8 +103,8 @@ class Help {
|
|
|
100
103
|
return output + '\n';
|
|
101
104
|
}
|
|
102
105
|
command(command) {
|
|
103
|
-
const help = new command_1.default(this.config, this.opts);
|
|
104
|
-
return help.
|
|
106
|
+
const help = new command_1.default(command, this.config, this.opts);
|
|
107
|
+
return help.generate();
|
|
105
108
|
}
|
|
106
109
|
topics(topics) {
|
|
107
110
|
if (!topics.length)
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.1
|
|
1
|
+
{"version":"2.2.1","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,40 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-help",
|
|
3
3
|
"description": "standard help for oclif",
|
|
4
|
-
"version": "2.1
|
|
4
|
+
"version": "2.2.1",
|
|
5
5
|
"author": "Jeff Dickey @jdxcode",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-help/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@oclif/command": "^1.5.
|
|
8
|
+
"@oclif/command": "^1.5.13",
|
|
9
9
|
"chalk": "^2.4.1",
|
|
10
10
|
"indent-string": "^3.2.0",
|
|
11
11
|
"lodash.template": "^4.4.0",
|
|
12
|
-
"string-width": "^
|
|
12
|
+
"string-width": "^3.0.0",
|
|
13
13
|
"strip-ansi": "^5.0.0",
|
|
14
|
-
"widest-line": "^2.0.
|
|
14
|
+
"widest-line": "^2.0.1",
|
|
15
15
|
"wrap-ansi": "^4.0.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@oclif/config": "^1.
|
|
19
|
-
"@oclif/dev-cli": "^1.
|
|
18
|
+
"@oclif/config": "^1.13.0",
|
|
19
|
+
"@oclif/dev-cli": "^1.21.0",
|
|
20
20
|
"@oclif/errors": "^1.2.2",
|
|
21
|
-
"@oclif/plugin-legacy": "^1.1.
|
|
22
|
-
"@oclif/plugin-plugins": "^1.7.
|
|
23
|
-
"@oclif/test": "^1.2.
|
|
21
|
+
"@oclif/plugin-legacy": "^1.1.3",
|
|
22
|
+
"@oclif/plugin-plugins": "^1.7.6",
|
|
23
|
+
"@oclif/test": "^1.2.2",
|
|
24
24
|
"@oclif/tslint": "^3.1.1",
|
|
25
|
-
"@types/chai": "^4.1.
|
|
26
|
-
"@types/indent-string": "^3.
|
|
25
|
+
"@types/chai": "^4.1.7",
|
|
26
|
+
"@types/indent-string": "^3.2.0",
|
|
27
27
|
"@types/lodash.template": "^4.4.4",
|
|
28
28
|
"@types/mocha": "^5.2.5",
|
|
29
|
-
"@types/node": "^10.
|
|
29
|
+
"@types/node": "^10.12.19",
|
|
30
30
|
"@types/strip-ansi": "^3.0.0",
|
|
31
31
|
"@types/wrap-ansi": "^3.0.0",
|
|
32
32
|
"chai": "^4.2.0",
|
|
33
|
-
"globby": "^
|
|
33
|
+
"globby": "^9.0.0",
|
|
34
34
|
"mocha": "^5.2.0",
|
|
35
|
-
"ts-node": "^
|
|
36
|
-
"tslint": "^5.
|
|
37
|
-
"typescript": "^3.
|
|
35
|
+
"ts-node": "^8.0.2",
|
|
36
|
+
"tslint": "^5.12.1",
|
|
37
|
+
"typescript": "^3.2.4"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=8.0.0"
|