@oclif/plugin-help 2.1.6 → 2.2.3

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/command.js CHANGED
@@ -5,7 +5,8 @@ const indent = require("indent-string");
5
5
  const stripAnsi = require("strip-ansi");
6
6
  const list_1 = require("./list");
7
7
  const util_1 = require("./util");
8
- let { underline, dim, bold, } = chalk_1.default;
8
+ const { underline, bold, } = chalk_1.default;
9
+ let { dim, } = chalk_1.default;
9
10
  if (process.env.ConEmuANSI === 'ON') {
10
11
  dim = chalk_1.default.gray;
11
12
  }
@@ -40,7 +41,7 @@ class CommandHelp {
40
41
  }
41
42
  usage(flags) {
42
43
  const usage = this.command.usage;
43
- let body = (usage ? util_1.castArray(usage) : [this.defaultUsage(flags)])
44
+ const body = (usage ? util_1.castArray(usage) : [this.defaultUsage(flags)])
44
45
  .map(u => `$ ${this.config.bin} ${u}`.trim())
45
46
  .join('\n');
46
47
  return [
@@ -56,7 +57,7 @@ class CommandHelp {
56
57
  }
57
58
  description() {
58
59
  const cmd = this.command;
59
- let description = cmd.description && this.render(cmd.description).split('\n').slice(1).join('\n');
60
+ const description = cmd.description && this.render(cmd.description).split('\n').slice(1).join('\n');
60
61
  if (!description)
61
62
  return;
62
63
  return [
@@ -65,27 +66,27 @@ class CommandHelp {
65
66
  ].join('\n');
66
67
  }
67
68
  aliases(aliases) {
68
- if (!aliases || !aliases.length)
69
+ if (!aliases || aliases.length === 0)
69
70
  return;
70
- let body = aliases.map(a => ['$', this.config.bin, a].join(' ')).join('\n');
71
+ const body = aliases.map(a => ['$', this.config.bin, a].join(' ')).join('\n');
71
72
  return [
72
73
  bold('ALIASES'),
73
74
  indent(wrap(body, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
74
75
  ].join('\n');
75
76
  }
76
77
  examples(examples) {
77
- if (!examples || !examples.length)
78
+ if (!examples || examples.length === 0)
78
79
  return;
79
- let body = util_1.castArray(examples).map(a => this.render(a)).join('\n');
80
+ const body = util_1.castArray(examples).map(a => this.render(a)).join('\n');
80
81
  return [
81
82
  bold('EXAMPLE' + (examples.length > 1 ? 'S' : '')),
82
83
  indent(wrap(body, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
83
84
  ].join('\n');
84
85
  }
85
86
  args(args) {
86
- if (!args.filter(a => a.description).length)
87
+ if (args.filter(a => a.description).length === 0)
87
88
  return;
88
- let body = list_1.renderList(args.map(a => {
89
+ const body = list_1.renderList(args.map(a => {
89
90
  const name = a.name.toUpperCase();
90
91
  let description = a.description || '';
91
92
  if (a.default)
@@ -100,27 +101,30 @@ class CommandHelp {
100
101
  ].join('\n');
101
102
  }
102
103
  arg(arg) {
103
- let name = arg.name.toUpperCase();
104
+ const name = arg.name.toUpperCase();
104
105
  if (arg.required)
105
106
  return `${name}`;
106
107
  return `[${name}]`;
107
108
  }
108
109
  flags(flags) {
109
- if (!flags.length)
110
+ if (flags.length === 0)
110
111
  return;
111
- let body = list_1.renderList(flags.map(flag => {
112
- const label = [];
113
- if (flag.char)
114
- label.push(`-${flag.char[0]}`);
115
- if (flag.name) {
116
- if (flag.type === 'boolean' && flag.allowNo) {
117
- label.push(`--[no-]${flag.name.trim()}`);
118
- }
119
- else {
120
- label.push(`--${flag.name.trim()}`);
112
+ const body = list_1.renderList(flags.map(flag => {
113
+ let left = flag.helpLabel;
114
+ if (!left) {
115
+ const label = [];
116
+ if (flag.char)
117
+ label.push(`-${flag.char[0]}`);
118
+ if (flag.name) {
119
+ if (flag.type === 'boolean' && flag.allowNo) {
120
+ label.push(`--[no-]${flag.name.trim()}`);
121
+ }
122
+ else {
123
+ label.push(`--${flag.name.trim()}`);
124
+ }
121
125
  }
126
+ left = label.join(', ');
122
127
  }
123
- let left = label.join(', ');
124
128
  if (flag.type === 'option') {
125
129
  let value = flag.helpValue || flag.name;
126
130
  if (!flag.helpValue && flag.options) {
@@ -5,16 +5,16 @@ const __1 = require("..");
5
5
  class HelpCommand extends command_1.Command {
6
6
  async run() {
7
7
  const { flags, argv } = this.parse(HelpCommand);
8
- let help = new __1.default(this.config, { all: flags.all });
8
+ const help = new __1.default(this.config, { all: flags.all });
9
9
  help.showHelp(argv);
10
10
  }
11
11
  }
12
+ exports.default = HelpCommand;
12
13
  HelpCommand.description = 'display help for <%= config.bin %>';
13
14
  HelpCommand.flags = {
14
15
  all: command_1.flags.boolean({ description: 'see all commands in CLI' }),
15
16
  };
16
17
  HelpCommand.args = [
17
- { name: 'command', required: false, description: 'command to show help for' }
18
+ { name: 'command', required: false, description: 'command to show help for' },
18
19
  ];
19
20
  HelpCommand.strict = false;
20
- exports.default = HelpCommand;
package/lib/index.js CHANGED
@@ -11,6 +11,20 @@ const screen_1 = require("./screen");
11
11
  const util_1 = require("./util");
12
12
  const wrap = require('wrap-ansi');
13
13
  const { bold, } = chalk_1.default;
14
+ function getHelpSubject(args) {
15
+ // special case
16
+ // if (['help:help', 'help:--help', '--help:help'].includes(argv.slice(0, 2).join(':'))) {
17
+ // if (argv[0] === 'help') return 'help'
18
+ for (const arg of args) {
19
+ if (arg === '--')
20
+ return;
21
+ if (arg.startsWith('-'))
22
+ continue;
23
+ if (arg === 'help')
24
+ continue;
25
+ return arg;
26
+ }
27
+ }
14
28
  class Help {
15
29
  constructor(config, opts = {}) {
16
30
  this.config = config;
@@ -18,47 +32,39 @@ class Help {
18
32
  this.render = util_1.template(this);
19
33
  }
20
34
  showHelp(argv) {
21
- const getHelpSubject = () => {
22
- // special case
23
- // if (['help:help', 'help:--help', '--help:help'].includes(argv.slice(0, 2).join(':'))) {
24
- // if (argv[0] === 'help') return 'help'
25
- for (let arg of argv) {
26
- if (arg === '--')
27
- return;
28
- if (arg.startsWith('-'))
29
- continue;
30
- if (arg === 'help')
31
- continue;
32
- return arg;
33
- }
34
- };
35
35
  let topics = this.config.topics;
36
36
  topics = topics.filter(t => this.opts.all || !t.hidden);
37
37
  topics = util_1.sortBy(topics, t => t.name);
38
38
  topics = util_1.uniqBy(topics, t => t.name);
39
- let subject = getHelpSubject();
39
+ const subject = getHelpSubject(argv);
40
40
  let command;
41
+ if (subject) {
42
+ command = this.config.findCommand(subject);
43
+ }
41
44
  let topic;
45
+ if (subject && !command) {
46
+ topic = this.config.findTopic(subject);
47
+ }
42
48
  if (!subject) {
43
49
  console.log(this.root());
44
- console.log();
50
+ console.log('');
45
51
  if (!this.opts.all) {
46
52
  topics = topics.filter(t => !t.name.includes(':'));
47
53
  }
48
54
  console.log(this.topics(topics));
49
- console.log();
55
+ console.log('');
50
56
  }
51
- else if (command = this.config.findCommand(subject)) {
57
+ else if (command) {
52
58
  this.showCommandHelp(command, topics);
53
59
  }
54
- else if (topic = this.config.findTopic(subject)) {
60
+ else if (topic) {
55
61
  const name = topic.name;
56
62
  const depth = name.split(':').length;
57
63
  topics = topics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
58
64
  console.log(this.topic(topic));
59
- if (topics.length) {
65
+ if (topics.length > 0) {
60
66
  console.log(this.topics(topics));
61
- console.log();
67
+ console.log('');
62
68
  }
63
69
  }
64
70
  else {
@@ -69,14 +75,14 @@ class Help {
69
75
  const name = command.id;
70
76
  const depth = name.split(':').length;
71
77
  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];
78
+ const title = command.description && this.render(command.description).split('\n')[0];
73
79
  if (title)
74
80
  console.log(title + '\n');
75
81
  console.log(this.command(command));
76
- console.log();
77
- if (topics.length) {
82
+ console.log('');
83
+ if (topics.length > 0) {
78
84
  console.log(this.topics(topics));
79
- console.log();
85
+ console.log('');
80
86
  }
81
87
  }
82
88
  root() {
@@ -85,7 +91,7 @@ class Help {
85
91
  }
86
92
  topic(topic) {
87
93
  let description = this.render(topic.description || '');
88
- let title = description.split('\n')[0];
94
+ const title = description.split('\n')[0];
89
95
  description = description.split('\n').slice(1).join('\n');
90
96
  let output = util_1.compact([
91
97
  title,
@@ -95,8 +101,8 @@ class Help {
95
101
  ].join('\n'),
96
102
  description && ([
97
103
  bold('DESCRIPTION'),
98
- indent(wrap(description, this.opts.maxWidth - 2, { trim: false, hard: true }), 2)
99
- ].join('\n'))
104
+ indent(wrap(description, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
105
+ ].join('\n')),
100
106
  ]).join('\n\n');
101
107
  if (this.opts.stripAnsi)
102
108
  output = stripAnsi(output);
@@ -107,11 +113,11 @@ class Help {
107
113
  return help.generate();
108
114
  }
109
115
  topics(topics) {
110
- if (!topics.length)
116
+ if (topics.length === 0)
111
117
  return;
112
- let body = list_1.renderList(topics.map(c => [
118
+ const body = list_1.renderList(topics.map(c => [
113
119
  c.name,
114
- c.description && this.render(c.description.split('\n')[0])
120
+ c.description && this.render(c.description.split('\n')[0]),
115
121
  ]), {
116
122
  spacer: '\n',
117
123
  stripAnsi: this.opts.stripAnsi,
package/lib/list.js CHANGED
@@ -10,7 +10,7 @@ function renderList(input, opts) {
10
10
  return '';
11
11
  }
12
12
  const renderMultiline = () => {
13
- output = '';
13
+ let output = '';
14
14
  for (let [left, right] of input) {
15
15
  if (!left && !right)
16
16
  continue;
@@ -35,7 +35,8 @@ function renderList(input, opts) {
35
35
  let output = '';
36
36
  let spacer = opts.spacer || '\n';
37
37
  let cur = '';
38
- for (let [left, right] of input) {
38
+ for (const [left, r] of input) {
39
+ let right = r;
39
40
  if (cur) {
40
41
  output += spacer;
41
42
  output += cur;
package/lib/screen.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare let stdtermwidth: number;
2
- export declare let errtermwidth: number;
1
+ export declare const stdtermwidth: number;
2
+ export declare const errtermwidth: number;
package/lib/util.d.ts CHANGED
@@ -5,4 +5,4 @@ export declare function sortBy<T>(arr: T[], fn: (i: T) => sort.Types | sort.Type
5
5
  export declare namespace sort {
6
6
  type Types = string | number | undefined | boolean;
7
7
  }
8
- export declare const template: (context: any) => (t: string) => string;
8
+ export declare function template(context: any): (t: string) => string;
package/lib/util.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const Template = require("lodash.template");
3
+ const lodashTemplate = require("lodash.template");
4
4
  function uniqBy(arr, fn) {
5
5
  return arr.filter((a, i) => {
6
- let aVal = fn(a);
6
+ const aVal = fn(a);
7
7
  return !arr.find((b, j) => j > i && fn(b) === aVal);
8
8
  });
9
9
  }
10
10
  exports.uniqBy = uniqBy;
11
11
  function compact(a) {
12
- return a.filter((a) => !!a);
12
+ return a.filter((a) => Boolean(a));
13
13
  }
14
14
  exports.compact = compact;
15
15
  function castArray(input) {
@@ -25,7 +25,7 @@ function sortBy(arr, fn) {
25
25
  if (Array.isArray(a) && Array.isArray(b)) {
26
26
  if (a.length === 0 && b.length === 0)
27
27
  return 0;
28
- let diff = compare(a[0], b[0]);
28
+ const diff = compare(a[0], b[0]);
29
29
  if (diff !== 0)
30
30
  return diff;
31
31
  return compare(a.slice(1), b.slice(1));
@@ -39,4 +39,10 @@ function sortBy(arr, fn) {
39
39
  return arr.sort((a, b) => compare(fn(a), fn(b)));
40
40
  }
41
41
  exports.sortBy = sortBy;
42
- exports.template = (context) => (t) => Template(t)(context);
42
+ function template(context) {
43
+ function render(t) {
44
+ return lodashTemplate(t)(context);
45
+ }
46
+ return render;
47
+ }
48
+ exports.template = template;
@@ -1 +1 @@
1
- {"version":"2.1.6","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}]}}}
1
+ {"version":"2.2.3","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,13 @@
1
1
  {
2
2
  "name": "@oclif/plugin-help",
3
3
  "description": "standard help for oclif",
4
- "version": "2.1.6",
4
+ "version": "2.2.3",
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",
8
+ "@oclif/command": "^1.5.13",
9
9
  "chalk": "^2.4.1",
10
- "indent-string": "^3.2.0",
10
+ "indent-string": "^4.0.0",
11
11
  "lodash.template": "^4.4.0",
12
12
  "string-width": "^3.0.0",
13
13
  "strip-ansi": "^5.0.0",
@@ -15,26 +15,26 @@
15
15
  "wrap-ansi": "^4.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@oclif/config": "^1.12.0",
18
+ "@oclif/config": "^1.13.0",
19
19
  "@oclif/dev-cli": "^1.21.0",
20
20
  "@oclif/errors": "^1.2.2",
21
21
  "@oclif/plugin-legacy": "^1.1.3",
22
22
  "@oclif/plugin-plugins": "^1.7.6",
23
23
  "@oclif/test": "^1.2.2",
24
- "@oclif/tslint": "^3.1.1",
25
24
  "@types/chai": "^4.1.7",
26
- "@types/indent-string": "^3.2.0",
27
25
  "@types/lodash.template": "^4.4.4",
28
26
  "@types/mocha": "^5.2.5",
29
- "@types/node": "^10.12.19",
27
+ "@types/node": "^8.10.59",
30
28
  "@types/strip-ansi": "^3.0.0",
31
29
  "@types/wrap-ansi": "^3.0.0",
32
30
  "chai": "^4.2.0",
31
+ "eslint": "^6.6.0",
32
+ "eslint-config-oclif": "^3.1.0",
33
+ "eslint-config-oclif-typescript": "^0.1.0",
33
34
  "globby": "^9.0.0",
34
35
  "mocha": "^5.2.0",
35
36
  "ts-node": "^8.0.2",
36
- "tslint": "^5.12.1",
37
- "typescript": "^3.2.4"
37
+ "typescript": "^3.7.2"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=8.0.0"
@@ -60,11 +60,12 @@
60
60
  "repository": "oclif/plugin-help",
61
61
  "scripts": {
62
62
  "build": "rm -rf lib && tsc",
63
- "lint": "tsc -p test --noEmit && tslint -p test",
64
- "postpack": "rm oclif.manifest.json",
65
- "posttest": "yarn run lint",
63
+ "lint": "eslint . --ext .ts --config .eslintrc",
64
+ "pretest": "tsc -p test --noEmit",
65
+ "test": "mocha --forbid-only \"test/**/*.test.ts\"",
66
+ "posttest": "yarn lint",
66
67
  "prepack": "yarn run build && oclif-dev manifest",
67
- "test": "mocha --forbid-only \"test/**/*.test.ts\""
68
+ "postpack": "rm oclif.manifest.json"
68
69
  },
69
70
  "types": "./lib/index.d.ts"
70
71
  }