@oclif/plugin-commands 2.1.0 → 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 +7 -0
- package/README.md +5 -4
- package/lib/commands/commands.d.ts +1 -1
- package/lib/commands/commands.js +10 -2
- package/lib/utils/tree.d.ts +4 -0
- package/lib/utils/tree.js +27 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.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
|
+
|
|
5
12
|
## [2.1.0](https://github.com/oclif/plugin-commands/compare/v2.0.2...v2.1.0) (2022-01-28)
|
|
6
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -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.
|
|
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,8 +37,8 @@ list all the commands
|
|
|
37
37
|
|
|
38
38
|
```
|
|
39
39
|
USAGE
|
|
40
|
-
$ oclif-example commands [--json] [-h] [--hidden] [--columns <value> | -x] [--sort <value>]
|
|
41
|
-
<value>] [--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.
|
|
@@ -52,6 +52,7 @@ FLAGS
|
|
|
52
52
|
--output=<option> output in a more machine friendly format
|
|
53
53
|
<options: csv|json|yaml>
|
|
54
54
|
--sort=<value> property to sort by (prepend '-' for descending)
|
|
55
|
+
--tree show tree of commands
|
|
55
56
|
|
|
56
57
|
GLOBAL FLAGS
|
|
57
58
|
--json Format output as json.
|
|
@@ -60,5 +61,5 @@ DESCRIPTION
|
|
|
60
61
|
list all the commands
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v2.
|
|
64
|
+
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v2.2.0/src/commands/commands.ts)_
|
|
64
65
|
<!-- commandsstop -->
|
|
@@ -3,7 +3,7 @@ export default class Commands extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static enableJsonFlag: boolean;
|
|
5
5
|
static flags: any;
|
|
6
|
-
run(): Promise<unknown[] | undefined>;
|
|
6
|
+
run(): Promise<unknown[] | import("@oclif/core/lib/cli-ux/styled/tree").Tree | undefined>;
|
|
7
7
|
private getCommands;
|
|
8
8
|
private removeCycles;
|
|
9
9
|
}
|
package/lib/commands/commands.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const core_1 = require("@oclif/core");
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const os_1 = require("os");
|
|
6
|
+
const tree_1 = require("../utils/tree");
|
|
6
7
|
class Commands extends core_1.Command {
|
|
7
8
|
async run() {
|
|
8
9
|
const { flags } = await this.parse(Commands);
|
|
@@ -19,7 +20,7 @@ class Commands extends core_1.Command {
|
|
|
19
20
|
command.id = (0, core_1.toConfiguredId)(command.id, this.config);
|
|
20
21
|
return command;
|
|
21
22
|
});
|
|
22
|
-
if (this.jsonEnabled()) {
|
|
23
|
+
if (this.jsonEnabled() && !flags.tree) {
|
|
23
24
|
const formatted = await Promise.all(commands.map(async (cmd) => {
|
|
24
25
|
let commandClass = await cmd.load();
|
|
25
26
|
const obj = Object.assign(Object.assign({}, cmd), commandClass);
|
|
@@ -35,6 +36,13 @@ class Commands extends core_1.Command {
|
|
|
35
36
|
}));
|
|
36
37
|
return formatted;
|
|
37
38
|
}
|
|
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;
|
|
45
|
+
}
|
|
38
46
|
core_1.CliUx.ux.table(commands.map(command => {
|
|
39
47
|
// Massage some fields so it looks good in the table
|
|
40
48
|
command.description = (command.description || '').split(os_1.EOL)[0];
|
|
@@ -105,4 +113,4 @@ class Commands extends core_1.Command {
|
|
|
105
113
|
exports.default = Commands;
|
|
106
114
|
Commands.description = 'list all the commands';
|
|
107
115
|
Commands.enableJsonFlag = true;
|
|
108
|
-
Commands.flags = Object.assign({ help: core_1.Flags.help({ char: 'h' }), hidden: core_1.Flags.boolean({ description: 'show hidden commands' }) }, core_1.CliUx.ux.table.flags());
|
|
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,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;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.
|
|
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