@oclif/plugin-commands 2.2.27 → 3.0.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/README.md CHANGED
@@ -1,33 +1,35 @@
1
- @oclif/plugin-commands
2
- ======================
1
+ # @oclif/plugin-commands
3
2
 
4
3
  plugin to show the list of all the commands
5
4
 
6
5
  [![Version](https://img.shields.io/npm/v/@oclif/plugin-commands.svg)](https://npmjs.org/package/@oclif/plugin-commands)
7
- [![CircleCI](https://circleci.com/gh/oclif/plugin-commands/tree/main.svg?style=shield)](https://circleci.com/gh/oclif/plugin-commands/tree/main)
8
- [![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/plugin-commands?branch=main&svg=true)](https://ci.appveyor.com/project/oclif/plugin-commands/branch/main)
9
6
  [![Downloads/week](https://img.shields.io/npm/dw/@oclif/plugin-commands.svg)](https://npmjs.org/package/@oclif/plugin-commands)
10
7
  [![License](https://img.shields.io/npm/l/@oclif/plugin-commands.svg)](https://github.com/oclif/plugin-commands/blob/main/package.json)
11
8
 
12
9
  <!-- toc -->
10
+ * [@oclif/plugin-commands](#oclifplugin-commands)
13
11
  * [Usage](#usage)
14
12
  * [Commands](#commands)
15
13
  <!-- tocstop -->
14
+
16
15
  # Usage
16
+
17
17
  <!-- usage -->
18
18
  ```sh-session
19
19
  $ npm install -g @oclif/plugin-commands
20
20
  $ oclif-example COMMAND
21
21
  running command...
22
22
  $ oclif-example (--version)
23
- @oclif/plugin-commands/2.2.27 linux-x64 node-v18.18.0
23
+ @oclif/plugin-commands/3.0.1 linux-x64 node-v18.18.0
24
24
  $ oclif-example --help [COMMAND]
25
25
  USAGE
26
26
  $ oclif-example COMMAND
27
27
  ...
28
28
  ```
29
29
  <!-- usagestop -->
30
+
30
31
  # Commands
32
+
31
33
  <!-- commands -->
32
34
  * [`oclif-example commands`](#oclif-example-commands)
33
35
 
@@ -37,8 +39,8 @@ list all the commands
37
39
 
38
40
  ```
39
41
  USAGE
40
- $ oclif-example commands [--json] [-h] [--hidden] [--tree] [--columns <value> | -x] [--sort <value>]
41
- [--filter <value>] [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
42
+ $ oclif-example commands [--json] [-h] [--hidden] [--tree] [--columns <value> | -x] [--filter <value>]
43
+ [--no-header | [--csv | --no-truncate]] [--output csv|json|yaml | | ] [--sort <value>]
42
44
 
43
45
  FLAGS
44
46
  -h, --help Show CLI help.
@@ -61,5 +63,5 @@ DESCRIPTION
61
63
  list all the commands
62
64
  ```
63
65
 
64
- _See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v2.2.27/src/commands/commands.ts)_
66
+ _See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v3.0.1/src/commands/commands.ts)_
65
67
  <!-- commandsstop -->
@@ -3,19 +3,19 @@ export default class Commands extends Command {
3
3
  static description: string;
4
4
  static enableJsonFlag: boolean;
5
5
  static flags: {
6
- columns: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
- sort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
- filter: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
- csv: import("@oclif/core/lib/interfaces").Flag<boolean>;
10
- output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
- extended: import("@oclif/core/lib/interfaces").Flag<boolean>;
12
- 'no-truncate': import("@oclif/core/lib/interfaces").Flag<boolean>;
13
- 'no-header': import("@oclif/core/lib/interfaces").Flag<boolean>;
14
- help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
15
- hidden: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
- tree: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
6
+ columns: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined>;
7
+ csv: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
8
+ extended: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
+ filter: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined>;
10
+ 'no-header': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
11
+ 'no-truncate': import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
12
+ output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined>;
13
+ sort: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined>;
14
+ help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
15
+ hidden: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
16
+ tree: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
17
17
  };
18
- run(): Promise<unknown[] | import("@oclif/core/lib/cli-ux/styled/tree").Tree | undefined>;
18
+ run(): Promise<unknown[] | import("@oclif/core/lib/cli-ux/styled/tree.js").Tree | undefined>;
19
19
  private getCommands;
20
20
  private removeCycles;
21
21
  }
@@ -1,76 +1,85 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
4
- const _ = require("lodash");
5
- const os_1 = require("os");
6
- const tree_1 = require("../utils/tree");
7
- class Commands extends core_1.Command {
1
+ import { Command, Flags, toConfiguredId, ux } from '@oclif/core';
2
+ import pickBy from 'lodash.pickby';
3
+ import sortBy from 'lodash.sortby';
4
+ import template from 'lodash.template';
5
+ import uniqBy from 'lodash.uniqby';
6
+ import { EOL } from 'node:os';
7
+ import createCommandTree from '../utils/tree.js';
8
+ export default class Commands extends Command {
9
+ static description = 'list all the commands';
10
+ static enableJsonFlag = true;
11
+ static flags = {
12
+ help: Flags.help({ char: 'h' }),
13
+ hidden: Flags.boolean({ description: 'show hidden commands' }),
14
+ tree: Flags.boolean({ description: 'show tree of commands' }),
15
+ ...ux.table.flags(),
16
+ };
8
17
  async run() {
9
18
  const { flags } = await this.parse(Commands);
10
19
  let commands = this.getCommands();
11
20
  if (!flags.hidden) {
12
- commands = commands.filter(c => !c.hidden);
21
+ commands = commands.filter((c) => !c.hidden);
13
22
  }
14
- const config = this.config;
15
- commands = _.sortBy(commands, 'id').map(command => {
23
+ const { config } = this;
24
+ commands = sortBy(commands, 'id').map((command) => {
16
25
  // Template supported fields.
17
- command.description = (typeof command.description === 'string' && _.template(command.description)({ command, config })) || undefined;
18
- command.summary = (typeof command.summary === 'string' && _.template(command.summary)({ command, config })) || undefined;
19
- command.usage = (typeof command.usage === 'string' && _.template(command.usage)({ command, config })) || undefined;
20
- command.id = (0, core_1.toConfiguredId)(command.id, this.config);
26
+ command.description =
27
+ (typeof command.description === 'string' && template(command.description)({ command, config })) || undefined;
28
+ command.summary =
29
+ (typeof command.summary === 'string' && template(command.summary)({ command, config })) || undefined;
30
+ command.usage = (typeof command.usage === 'string' && template(command.usage)({ command, config })) || undefined;
31
+ command.id = toConfiguredId(command.id, config);
21
32
  return command;
22
33
  });
23
34
  if (this.jsonEnabled() && !flags.tree) {
24
35
  const formatted = await Promise.all(commands.map(async (cmd) => {
25
- // @ts-expect-error
26
- let commandClass = {};
36
+ let commandClass;
27
37
  try {
28
38
  commandClass = await cmd.load();
29
39
  }
30
40
  catch (error) {
31
41
  this.debug(error);
32
42
  }
33
- const obj = Object.assign(Object.assign({}, cmd), commandClass);
43
+ const obj = { ...cmd, ...commandClass };
34
44
  // Load all properties on all extending classes.
35
45
  while (commandClass !== undefined) {
36
- commandClass = Object.getPrototypeOf(commandClass) || undefined;
46
+ commandClass = Object.getPrototypeOf(commandClass) ?? undefined;
37
47
  // ES2022 will return all unset static properties on the prototype as undefined. This is different from ES2021
38
48
  // which only returns the static properties that are set by defaults. In order to prevent
39
49
  // Object.assign from overwriting the properties on the object, we need to filter out the undefined values.
40
- Object.assign(obj, _.pickBy(commandClass, v => v !== undefined));
50
+ Object.assign(obj, pickBy(commandClass, (v) => v !== undefined));
41
51
  }
42
52
  // The plugin property on the loaded class contains a LOT of information including all the commands again. Remove it.
43
53
  delete obj.plugin;
44
54
  // If Command classes have circular references, don't break the commands command.
45
55
  return this.removeCycles(obj);
46
56
  }));
47
- return _.uniqBy(formatted, 'id');
57
+ return uniqBy(formatted, 'id');
48
58
  }
49
59
  if (flags.tree) {
50
- const tree = (0, tree_1.default)(commands, this.config.topicSeparator);
60
+ const tree = createCommandTree(commands, config.topicSeparator);
51
61
  if (!this.jsonEnabled()) {
52
62
  tree.display();
53
63
  }
54
64
  return tree;
55
65
  }
56
- core_1.ux.table(commands.map(command => {
66
+ ux.table(commands.map((command) => {
57
67
  // Massage some fields so it looks good in the table
58
- command.description = (command.description || '').split(os_1.EOL)[0];
59
- command.summary = (command.summary || (command.description || '').split(os_1.EOL)[0]);
68
+ command.description = (command.description ?? '').split(EOL)[0];
69
+ command.summary = command.summary ?? (command.description ?? '').split(EOL)[0];
60
70
  command.hidden = Boolean(command.hidden);
61
- command.usage = (command.usage || '');
71
+ command.usage ??= '';
62
72
  return command;
63
73
  }), {
64
- id: {
65
- header: 'Command',
66
- },
67
- summary: {},
68
74
  description: {
69
75
  extended: true,
70
76
  },
71
- usage: {
77
+ hidden: {
72
78
  extended: true,
73
79
  },
80
+ id: {
81
+ header: 'Command',
82
+ },
74
83
  pluginName: {
75
84
  extended: true,
76
85
  header: 'Plugin',
@@ -79,10 +88,15 @@ class Commands extends core_1.Command {
79
88
  extended: true,
80
89
  header: 'Type',
81
90
  },
82
- hidden: {
91
+ summary: {},
92
+ usage: {
83
93
  extended: true,
84
94
  },
85
- }, Object.assign({}, flags));
95
+ }, {
96
+ // to-do: investigate this oclif/core error when printLine is enabled
97
+ // printLine: this.log,
98
+ ...flags, // parsed flags
99
+ });
86
100
  }
87
101
  getCommands() {
88
102
  return this.config.commands;
@@ -95,10 +109,9 @@ class Commands extends core_1.Command {
95
109
  if (Object.prototype.toString.call(obj) === '[object Object]') {
96
110
  // We know it is a "Dictionary" because of the conditional
97
111
  const dictionary = obj;
98
- if (seenObjects.has(dictionary)) {
99
- // Seen, return undefined to remove.
100
- return undefined;
101
- }
112
+ // Seen, return undefined to remove.
113
+ if (seenObjects.has(dictionary))
114
+ return;
102
115
  seenObjects.set(dictionary, undefined);
103
116
  for (const key in dictionary) {
104
117
  // Delete the duplicate object if cycle found.
@@ -120,7 +133,3 @@ class Commands extends core_1.Command {
120
133
  return _removeCycles(object);
121
134
  }
122
135
  }
123
- exports.default = Commands;
124
- Commands.description = 'list all the commands';
125
- Commands.enableJsonFlag = true;
126
- Commands.flags = Object.assign({ help: core_1.Flags.help({ char: 'h' }), hidden: core_1.Flags.boolean({ description: 'show hidden commands' }), tree: core_1.Flags.boolean({ description: 'show tree of commands' }) }, core_1.ux.table.flags());
package/lib/index.js CHANGED
@@ -1,3 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {};
1
+ export default {};
@@ -1,4 +1,3 @@
1
1
  import { Command } from '@oclif/core';
2
- import { Tree } from '@oclif/core/lib/cli-ux/styled/tree';
3
- declare const createCommandTree: (commands: Command.Loadable[], topicSeparator?: string) => Tree;
2
+ declare const createCommandTree: (commands: Command.Loadable[], topicSeparator?: string) => import("@oclif/core/lib/cli-ux/styled/tree.js").Tree;
4
3
  export default createCommandTree;
package/lib/utils/tree.js CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const core_1 = require("@oclif/core");
1
+ import { ux } from '@oclif/core';
4
2
  const addNodes = (tree, commandParts) => {
5
3
  const existingNode = tree.search(commandParts[0]);
6
4
  // If the node exists and there's another part, add it to the node
@@ -17,11 +15,11 @@ const addNodes = (tree, commandParts) => {
17
15
  }
18
16
  };
19
17
  const createCommandTree = (commands, topicSeparator = ':') => {
20
- const tree = core_1.ux.tree();
21
- commands.forEach(command => {
18
+ const tree = ux.tree();
19
+ for (const command of commands) {
22
20
  const commandParts = command.id.split(topicSeparator);
23
21
  addNodes(tree, commandParts);
24
- });
22
+ }
25
23
  return tree;
26
24
  };
27
- exports.default = createCommandTree;
25
+ export default createCommandTree;