@oclif/plugin-commands 2.0.1 → 2.2.0

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 CHANGED
@@ -2,7 +2,21 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [2.0.1](https://github.com/oclif/plugin-commands/compare/v2.0.0...v2.0.1) (2021-12-08)
5
+ ## [2.2.0](https://github.com/oclif/plugin-commands/compare/v2.1.0...v2.2.0) (2022-06-17)
6
+
7
+
8
+ ### Features
9
+
10
+ * add a tree view for commands ([#292](https://github.com/oclif/plugin-commands/issues/292)) ([0ea4028](https://github.com/oclif/plugin-commands/commit/0ea402853f89507db41fce2adcdab99e33c14cf7))
11
+
12
+ ## [2.1.0](https://github.com/oclif/plugin-commands/compare/v2.0.2...v2.1.0) (2022-01-28)
13
+
14
+
15
+ ### Features
16
+
17
+ * remove cli-ux ([#257](https://github.com/oclif/plugin-commands/issues/257)) ([91d8696](https://github.com/oclif/plugin-commands/commit/91d8696bff375e622092744ab005daabf12c34d2))
18
+
19
+ ### [2.0.2](https://github.com/oclif/plugin-commands/compare/v2.0.0...v2.0.2) (2022-01-03)
6
20
 
7
21
 
8
22
  ### Bug Fixes
@@ -12,6 +26,7 @@ All notable changes to this project will be documented in this file. See [standa
12
26
  * bump deps ([#234](https://github.com/oclif/plugin-commands/issues/234)) ([04c903d](https://github.com/oclif/plugin-commands/commit/04c903d45a51987f6262628c7a401481dc237145))
13
27
  * bump deps and fix tests ([#236](https://github.com/oclif/plugin-commands/issues/236)) ([064da3f](https://github.com/oclif/plugin-commands/commit/064da3f22778c9625c640012b883eee8c1528ab1))
14
28
  * bump-deps ([#235](https://github.com/oclif/plugin-commands/issues/235)) ([55b3e59](https://github.com/oclif/plugin-commands/commit/55b3e59e0743078d2bf81bfa75a56ebd0b746c4b))
29
+ * use enableJsonFlag to enable json output ([#253](https://github.com/oclif/plugin-commands/issues/253)) ([5c839bc](https://github.com/oclif/plugin-commands/commit/5c839bc3d5b079c3080858ca4bc704283ff9d345))
15
30
 
16
31
  ## [1.2.2](https://github.com/oclif/plugin-commands/compare/v1.2.1...v1.2.2) (2018-10-13)
17
32
 
package/README.md CHANGED
@@ -4,10 +4,10 @@
4
4
  plugin to show the list of all the commands
5
5
 
6
6
  [![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/master.svg?style=shield)](https://circleci.com/gh/oclif/plugin-commands/tree/master)
8
- [![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/plugin-commands?branch=master&svg=true)](https://ci.appveyor.com/project/oclif/plugin-commands/branch/master)
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
9
  [![Downloads/week](https://img.shields.io/npm/dw/@oclif/plugin-commands.svg)](https://npmjs.org/package/@oclif/plugin-commands)
10
- [![License](https://img.shields.io/npm/l/@oclif/plugin-commands.svg)](https://github.com/oclif/plugin-commands/blob/master/package.json)
10
+ [![License](https://img.shields.io/npm/l/@oclif/plugin-commands.svg)](https://github.com/oclif/plugin-commands/blob/main/package.json)
11
11
 
12
12
  <!-- toc -->
13
13
  * [Usage](#usage)
@@ -20,7 +20,7 @@ $ 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.0.1 linux-x64 node-v12.22.7
23
+ @oclif/plugin-commands/2.2.0 linux-x64 node-v14.19.3
24
24
  $ oclif-example --help [COMMAND]
25
25
  USAGE
26
26
  $ oclif-example COMMAND
@@ -37,12 +37,11 @@ list all the commands
37
37
 
38
38
  ```
39
39
  USAGE
40
- $ oclif-example commands [-h] [-j] [--hidden] [--columns <value> | -x] [--sort <value>] [--filter <value>]
41
- [--output csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
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
42
 
43
43
  FLAGS
44
44
  -h, --help Show CLI help.
45
- -j, --json display unfiltered api data in json format
46
45
  -x, --extended show extra columns
47
46
  --columns=<value> only show provided columns (comma-separated)
48
47
  --csv output is csv format [alias: --output=csv]
@@ -53,10 +52,14 @@ FLAGS
53
52
  --output=<option> output in a more machine friendly format
54
53
  <options: csv|json|yaml>
55
54
  --sort=<value> property to sort by (prepend '-' for descending)
55
+ --tree show tree of commands
56
+
57
+ GLOBAL FLAGS
58
+ --json Format output as json.
56
59
 
57
60
  DESCRIPTION
58
61
  list all the commands
59
62
  ```
60
63
 
61
- _See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v2.0.1/src/commands/commands.ts)_
64
+ _See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v2.2.0/src/commands/commands.ts)_
62
65
  <!-- commandsstop -->
@@ -1,8 +1,9 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export default class Commands extends Command {
3
3
  static description: string;
4
+ static enableJsonFlag: boolean;
4
5
  static flags: any;
5
- run(): Promise<void>;
6
+ run(): Promise<unknown[] | import("@oclif/core/lib/cli-ux/styled/tree").Tree | undefined>;
6
7
  private getCommands;
7
8
  private removeCycles;
8
9
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
- const cli_ux_1 = require("cli-ux");
5
4
  const _ = require("lodash");
6
5
  const os_1 = require("os");
6
+ const tree_1 = require("../utils/tree");
7
7
  class Commands extends core_1.Command {
8
8
  async run() {
9
9
  const { flags } = await this.parse(Commands);
@@ -20,8 +20,8 @@ class Commands extends core_1.Command {
20
20
  command.id = (0, core_1.toConfiguredId)(command.id, this.config);
21
21
  return command;
22
22
  });
23
- if (flags.json) {
24
- cli_ux_1.ux.styledJSON(await Promise.all(commands.map(async (cmd) => {
23
+ if (this.jsonEnabled() && !flags.tree) {
24
+ const formatted = await Promise.all(commands.map(async (cmd) => {
25
25
  let commandClass = await cmd.load();
26
26
  const obj = Object.assign(Object.assign({}, cmd), commandClass);
27
27
  // Load all properties on all extending classes.
@@ -33,40 +33,46 @@ class Commands extends core_1.Command {
33
33
  delete obj.plugin;
34
34
  // If Command classes have circular references, don't break the commands command.
35
35
  return this.removeCycles(obj);
36
- })));
36
+ }));
37
+ return formatted;
37
38
  }
38
- else {
39
- cli_ux_1.ux.table(commands.map(command => {
40
- // Massage some fields so it looks good in the table
41
- command.description = (command.description || '').split(os_1.EOL)[0];
42
- command.summary = (command.summary || (command.description || '').split(os_1.EOL)[0]);
43
- command.hidden = Boolean(command.hidden);
44
- command.usage = (command.usage || '');
45
- return command;
46
- }), {
47
- id: {
48
- header: 'Command',
49
- },
50
- summary: {},
51
- description: {
52
- extended: true,
53
- },
54
- usage: {
55
- extended: true,
56
- },
57
- pluginName: {
58
- extended: true,
59
- header: 'Plugin',
60
- },
61
- pluginType: {
62
- extended: true,
63
- header: 'Type',
64
- },
65
- hidden: {
66
- extended: true,
67
- },
68
- }, Object.assign({}, flags));
39
+ if (flags.tree) {
40
+ const tree = (0, tree_1.default)(commands, this.config.topicSeparator);
41
+ if (!this.jsonEnabled()) {
42
+ tree.display();
43
+ }
44
+ return tree;
69
45
  }
46
+ core_1.CliUx.ux.table(commands.map(command => {
47
+ // Massage some fields so it looks good in the table
48
+ command.description = (command.description || '').split(os_1.EOL)[0];
49
+ command.summary = (command.summary || (command.description || '').split(os_1.EOL)[0]);
50
+ command.hidden = Boolean(command.hidden);
51
+ command.usage = (command.usage || '');
52
+ return command;
53
+ }), {
54
+ id: {
55
+ header: 'Command',
56
+ },
57
+ summary: {},
58
+ description: {
59
+ extended: true,
60
+ },
61
+ usage: {
62
+ extended: true,
63
+ },
64
+ pluginName: {
65
+ extended: true,
66
+ header: 'Plugin',
67
+ },
68
+ pluginType: {
69
+ extended: true,
70
+ header: 'Type',
71
+ },
72
+ hidden: {
73
+ extended: true,
74
+ },
75
+ }, Object.assign({}, flags));
70
76
  }
71
77
  getCommands() {
72
78
  return this.config.commands;
@@ -106,5 +112,5 @@ class Commands extends core_1.Command {
106
112
  }
107
113
  exports.default = Commands;
108
114
  Commands.description = 'list all the commands';
109
- // to-do: update this type when cli-ux is on core
110
- Commands.flags = Object.assign({ help: core_1.Flags.help({ char: 'h' }), json: core_1.Flags.boolean({ char: 'j', description: 'display unfiltered api data in json format' }), hidden: core_1.Flags.boolean({ description: 'show hidden commands' }) }, cli_ux_1.ux.table.flags());
115
+ Commands.enableJsonFlag = true;
116
+ 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.CliUx.ux.table.flags());
@@ -0,0 +1,4 @@
1
+ import { Interfaces } from '@oclif/core';
2
+ import { Tree } from '@oclif/core/lib/cli-ux/styled/tree';
3
+ declare const createCommandTree: (commands: Interfaces.Command[], topicSeparator?: string) => Tree;
4
+ export default createCommandTree;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const addNodes = (tree, commandParts) => {
5
+ const existingNode = tree.search(commandParts[0]);
6
+ // If the node exists and there's another part, add it to the node
7
+ if (existingNode && commandParts[1]) {
8
+ addNodes(existingNode, commandParts.slice(1));
9
+ }
10
+ else {
11
+ // The node doesn't exist, create it
12
+ tree.insert(commandParts[0]);
13
+ // If there are more parts, add them to the node
14
+ if (commandParts.length > 1) {
15
+ addNodes(tree.search(commandParts[0]), commandParts.slice(1));
16
+ }
17
+ }
18
+ };
19
+ const createCommandTree = (commands, topicSeparator = ':') => {
20
+ const tree = core_1.CliUx.ux.tree();
21
+ commands.forEach(command => {
22
+ const commandParts = command.id.split(topicSeparator);
23
+ addNodes(tree, commandParts);
24
+ });
25
+ return tree;
26
+ };
27
+ exports.default = createCommandTree;
@@ -1 +1 @@
1
- {"version":"2.0.1","commands":{"commands":{"id":"commands","description":"list all the commands","strict":true,"pluginName":"@oclif/plugin-commands","pluginAlias":"@oclif/plugin-commands","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"json":{"name":"json","type":"boolean","char":"j","description":"display unfiltered api data in json format","allowNo":false},"hidden":{"name":"hidden","type":"boolean","description":"show hidden commands","allowNo":false},"columns":{"name":"columns","type":"option","description":"only show provided columns (comma-separated)","multiple":false,"exclusive":["extended"]},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)","multiple":false},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo","multiple":false},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false,"exclusive":["no-truncate"]},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","multiple":false,"options":["csv","json","yaml"],"exclusive":["no-truncate","csv"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false,"exclusive":["columns"]},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false,"exclusive":["csv"]},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false,"exclusive":["csv"]}},"args":[]}}}
1
+ {"version":"2.2.0","commands":{"commands":{"id":"commands","description":"list all the commands","strict":true,"pluginName":"@oclif/plugin-commands","pluginAlias":"@oclif/plugin-commands","pluginType":"core","aliases":[],"flags":{"json":{"name":"json","type":"boolean","description":"Format output as json.","helpGroup":"GLOBAL","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"Show CLI help.","allowNo":false},"hidden":{"name":"hidden","type":"boolean","description":"show hidden commands","allowNo":false},"tree":{"name":"tree","type":"boolean","description":"show tree of commands","allowNo":false},"columns":{"name":"columns","type":"option","description":"only show provided columns (comma-separated)","multiple":false,"exclusive":["extended"]},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)","multiple":false},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo","multiple":false},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false,"exclusive":["no-truncate"]},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","multiple":false,"options":["csv","json","yaml"],"exclusive":["no-truncate","csv"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false,"exclusive":["columns"]},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false,"exclusive":["csv"]},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false,"exclusive":["csv"]}},"args":[],"enableJsonFlag":true}}}
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@oclif/plugin-commands",
3
3
  "description": "plugin to show the list of all the commands",
4
- "version": "2.0.1",
5
- "author": "Jeff Dickey @jdxcode",
4
+ "version": "2.2.0",
5
+ "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/plugin-commands/issues",
7
7
  "dependencies": {
8
- "@oclif/core": "^1.0.8",
9
- "cli-ux": "^6.0.5",
8
+ "@oclif/core": "^1.2.0",
10
9
  "lodash": "^4.17.11"
11
10
  },
12
11
  "devDependencies": {
@@ -25,7 +24,7 @@
25
24
  "mocha": "^8",
26
25
  "nock": "^13.0.0",
27
26
  "nyc": "^15.1.0",
28
- "oclif": "2.0.0-main.14",
27
+ "oclif": "^2.3.0",
29
28
  "shx": "^0.3.3",
30
29
  "ts-node": "^9.1.1",
31
30
  "tslib": "^2.0.0",