@oclif/plugin-commands 3.3.4 → 4.0.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/README.md +15 -19
- package/lib/commands/commands.d.ts +8 -13
- package/lib/commands/commands.js +113 -82
- package/oclif.manifest.json +37 -67
- package/package.json +12 -7
- package/lib/utils/tree.d.ts +0 -3
- package/lib/utils/tree.js +0 -25
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @oclif/plugin-commands
|
|
|
21
21
|
$ oclif-example COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ oclif-example (--version)
|
|
24
|
-
@oclif/plugin-commands/
|
|
24
|
+
@oclif/plugin-commands/4.0.0 linux-x64 node-v20.13.1
|
|
25
25
|
$ oclif-example --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ oclif-example COMMAND
|
|
@@ -36,36 +36,32 @@ USAGE
|
|
|
36
36
|
|
|
37
37
|
## `oclif-example commands`
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
List all oclif-example commands.
|
|
40
40
|
|
|
41
41
|
```
|
|
42
42
|
USAGE
|
|
43
|
-
$ oclif-example commands [--json] [
|
|
44
|
-
|
|
43
|
+
$ oclif-example commands [--json] [-c id|plugin|summary|type | --tree] [--deprecated] [-x | ] [--hidden]
|
|
44
|
+
[--no-truncate | ] [--sort id|plugin|summary|type | ]
|
|
45
45
|
|
|
46
46
|
FLAGS
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
--
|
|
51
|
-
--
|
|
52
|
-
--
|
|
53
|
-
--
|
|
54
|
-
|
|
55
|
-
--
|
|
56
|
-
--output=<option> output in a more machine friendly format
|
|
57
|
-
<options: csv|json|yaml>
|
|
58
|
-
--sort=<value> property to sort by (prepend '-' for descending)
|
|
59
|
-
--tree show tree of commands
|
|
47
|
+
-c, --columns=<option>... Only show provided columns (comma-separated).
|
|
48
|
+
<options: id|plugin|summary|type>
|
|
49
|
+
-x, --extended Show extra columns.
|
|
50
|
+
--deprecated Show deprecated commands.
|
|
51
|
+
--hidden Show hidden commands.
|
|
52
|
+
--no-truncate Do not truncate output.
|
|
53
|
+
--sort=<option> [default: id] Property to sort by.
|
|
54
|
+
<options: id|plugin|summary|type>
|
|
55
|
+
--tree Show tree of commands.
|
|
60
56
|
|
|
61
57
|
GLOBAL FLAGS
|
|
62
58
|
--json Format output as json.
|
|
63
59
|
|
|
64
60
|
DESCRIPTION
|
|
65
|
-
|
|
61
|
+
List all oclif-example commands.
|
|
66
62
|
```
|
|
67
63
|
|
|
68
|
-
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/
|
|
64
|
+
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v4.0.0/src/commands/commands.ts)_
|
|
69
65
|
<!-- commandsstop -->
|
|
70
66
|
|
|
71
67
|
# Contributing
|
|
@@ -3,20 +3,15 @@ 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/
|
|
7
|
-
|
|
8
|
-
extended: import("@oclif/core/
|
|
9
|
-
|
|
10
|
-
'no-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sort: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined>;
|
|
14
|
-
deprecated: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
15
|
-
help: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<void>;
|
|
16
|
-
hidden: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
17
|
-
tree: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
|
|
6
|
+
columns: import("@oclif/core/interfaces").OptionFlag<("type" | "id" | "summary" | "plugin")[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
deprecated: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
extended: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
hidden: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
'no-truncate': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
|
+
sort: import("@oclif/core/interfaces").OptionFlag<"type" | "id" | "summary" | "plugin", import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
tree: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
13
|
};
|
|
19
|
-
run(): Promise<unknown[]
|
|
14
|
+
run(): Promise<unknown[]>;
|
|
20
15
|
private getCommands;
|
|
21
16
|
private removeCycles;
|
|
22
17
|
}
|
package/lib/commands/commands.js
CHANGED
|
@@ -1,16 +1,59 @@
|
|
|
1
|
-
import { Command, Flags, toConfiguredId
|
|
1
|
+
import { Command, Flags, toConfiguredId } from '@oclif/core';
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
-
|
|
4
|
-
import
|
|
3
|
+
// @ts-expect-error because object-treeify does not have types: https://github.com/blackflux/object-treeify/issues/1077
|
|
4
|
+
import treeify from 'object-treeify';
|
|
5
|
+
import TtyTable from 'tty-table';
|
|
6
|
+
const COLUMNS = ['id', 'plugin', 'summary', 'type'];
|
|
7
|
+
function createTree(commands) {
|
|
8
|
+
const tree = {};
|
|
9
|
+
for (const command of commands) {
|
|
10
|
+
const parts = command.id.split(':');
|
|
11
|
+
let current = tree;
|
|
12
|
+
for (const part of parts) {
|
|
13
|
+
current[part] = current[part] || {};
|
|
14
|
+
current = current[part];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return tree;
|
|
18
|
+
}
|
|
19
|
+
function determineHeaders(columns, extended) {
|
|
20
|
+
const columnConfigs = {
|
|
21
|
+
id: { align: 'left', value: 'ID', width: '25%' },
|
|
22
|
+
plugin: { align: 'left', value: 'Plugin' },
|
|
23
|
+
summary: { align: 'left', value: 'Summary', width: '75%' },
|
|
24
|
+
type: { align: 'left', value: 'Type' },
|
|
25
|
+
};
|
|
26
|
+
if (columns) {
|
|
27
|
+
return columns.map((column) => columnConfigs[column]);
|
|
28
|
+
}
|
|
29
|
+
if (extended) {
|
|
30
|
+
return [columnConfigs.id, columnConfigs.summary, columnConfigs.plugin, columnConfigs.type];
|
|
31
|
+
}
|
|
32
|
+
return [columnConfigs.id, columnConfigs.summary];
|
|
33
|
+
}
|
|
5
34
|
export default class Commands extends Command {
|
|
6
|
-
static description = '
|
|
35
|
+
static description = 'List all <%= config.bin %> commands.';
|
|
7
36
|
static enableJsonFlag = true;
|
|
8
37
|
static flags = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
38
|
+
columns: Flags.custom({
|
|
39
|
+
char: 'c',
|
|
40
|
+
delimiter: ',',
|
|
41
|
+
description: 'Only show provided columns (comma-separated).',
|
|
42
|
+
exclusive: ['tree'],
|
|
43
|
+
multiple: true,
|
|
44
|
+
options: COLUMNS,
|
|
45
|
+
})(),
|
|
46
|
+
deprecated: Flags.boolean({ description: 'Show deprecated commands.' }),
|
|
47
|
+
extended: Flags.boolean({ char: 'x', description: 'Show extra columns.', exclusive: ['tree'] }),
|
|
48
|
+
hidden: Flags.boolean({ description: 'Show hidden commands.' }),
|
|
49
|
+
'no-truncate': Flags.boolean({ description: 'Do not truncate output.', exclusive: ['tree'] }),
|
|
50
|
+
sort: Flags.option({
|
|
51
|
+
default: 'id',
|
|
52
|
+
description: 'Property to sort by.',
|
|
53
|
+
exclusive: ['tree'],
|
|
54
|
+
options: COLUMNS,
|
|
55
|
+
})(),
|
|
56
|
+
tree: Flags.boolean({ description: 'Show tree of commands.' }),
|
|
14
57
|
};
|
|
15
58
|
async run() {
|
|
16
59
|
const { flags } = await this.parse(Commands);
|
|
@@ -23,82 +66,70 @@ export default class Commands extends Command {
|
|
|
23
66
|
commands = commands.filter((c) => c.state !== 'deprecated' && !deprecatedAliases.has(c.id));
|
|
24
67
|
}
|
|
25
68
|
const { config } = this;
|
|
26
|
-
commands = _.sortBy(commands,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
command.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
commands = _.sortBy(commands, flags.sort).map((command) =>
|
|
70
|
+
// Template supported fields.
|
|
71
|
+
({
|
|
72
|
+
...command,
|
|
73
|
+
description: (typeof command.description === 'string' && _.template(command.description)({ command, config })) || undefined,
|
|
74
|
+
summary: (typeof command.summary === 'string' && _.template(command.summary)({ command, config })) || undefined,
|
|
75
|
+
usage: (typeof command.usage === 'string' && _.template(command.usage)({ command, config })) || undefined,
|
|
76
|
+
}));
|
|
77
|
+
if (flags.tree) {
|
|
78
|
+
const tree = createTree(commands);
|
|
79
|
+
this.log(treeify(tree));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const headers = determineHeaders(flags.columns, flags.extended);
|
|
83
|
+
const extractData = (command) => headers.map((header) => {
|
|
84
|
+
switch (header.value) {
|
|
85
|
+
case 'ID': {
|
|
86
|
+
return toConfiguredId(command.id, config);
|
|
87
|
+
}
|
|
88
|
+
case 'Plugin': {
|
|
89
|
+
return command.pluginName;
|
|
90
|
+
}
|
|
91
|
+
case 'Type': {
|
|
92
|
+
return command.pluginType;
|
|
93
|
+
}
|
|
94
|
+
case 'Summary': {
|
|
95
|
+
return command.summary ?? command.description;
|
|
96
|
+
}
|
|
97
|
+
default: {
|
|
98
|
+
throw new Error('Unknown column');
|
|
99
|
+
}
|
|
53
100
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
101
|
+
});
|
|
102
|
+
// eslint-disable-next-line new-cap
|
|
103
|
+
const table = TtyTable(headers, commands.map((c) => extractData(c)), {
|
|
104
|
+
compact: true,
|
|
105
|
+
defaultValue: '',
|
|
106
|
+
truncate: flags['no-truncate'] ? undefined : '...',
|
|
107
|
+
});
|
|
108
|
+
this.log(table.render());
|
|
60
109
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
110
|
+
const json = _.uniqBy(await Promise.all(commands.map(async (cmd) => {
|
|
111
|
+
let commandClass;
|
|
112
|
+
try {
|
|
113
|
+
commandClass = await cmd.load();
|
|
65
114
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
pluginName: {
|
|
86
|
-
extended: true,
|
|
87
|
-
header: 'Plugin',
|
|
88
|
-
},
|
|
89
|
-
pluginType: {
|
|
90
|
-
extended: true,
|
|
91
|
-
header: 'Type',
|
|
92
|
-
},
|
|
93
|
-
summary: {},
|
|
94
|
-
usage: {
|
|
95
|
-
extended: true,
|
|
96
|
-
},
|
|
97
|
-
}, {
|
|
98
|
-
// to-do: investigate this oclif/core error when printLine is enabled
|
|
99
|
-
// printLine: this.log,
|
|
100
|
-
...flags, // parsed flags
|
|
101
|
-
});
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.debug(error);
|
|
117
|
+
}
|
|
118
|
+
const obj = { ...cmd, ...commandClass };
|
|
119
|
+
// Load all properties on all extending classes.
|
|
120
|
+
while (commandClass !== undefined) {
|
|
121
|
+
commandClass = Object.getPrototypeOf(commandClass) ?? undefined;
|
|
122
|
+
// ES2022 will return all unset static properties on the prototype as undefined. This is different from ES2021
|
|
123
|
+
// which only returns the static properties that are set by defaults. In order to prevent
|
|
124
|
+
// Object.assign from overwriting the properties on the object, we need to filter out the undefined values.
|
|
125
|
+
Object.assign(obj, _.pickBy(commandClass, (v) => v !== undefined));
|
|
126
|
+
}
|
|
127
|
+
// The plugin property on the loaded class contains a LOT of information including all the commands again. Remove it.
|
|
128
|
+
delete obj.plugin;
|
|
129
|
+
// If Command classes have circular references, don't break the commands command.
|
|
130
|
+
return this.removeCycles(obj);
|
|
131
|
+
})), 'id');
|
|
132
|
+
return json;
|
|
102
133
|
}
|
|
103
134
|
getCommands() {
|
|
104
135
|
return this.config.commands;
|
package/oclif.manifest.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"commands": {
|
|
4
4
|
"aliases": [],
|
|
5
5
|
"args": {},
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "List all <%= config.bin %> commands.",
|
|
7
7
|
"flags": {
|
|
8
8
|
"json": {
|
|
9
9
|
"description": "Format output as json.",
|
|
@@ -12,107 +12,77 @@
|
|
|
12
12
|
"allowNo": false,
|
|
13
13
|
"type": "boolean"
|
|
14
14
|
},
|
|
15
|
-
"deprecated": {
|
|
16
|
-
"description": "show deprecated commands",
|
|
17
|
-
"name": "deprecated",
|
|
18
|
-
"allowNo": false,
|
|
19
|
-
"type": "boolean"
|
|
20
|
-
},
|
|
21
|
-
"help": {
|
|
22
|
-
"char": "h",
|
|
23
|
-
"description": "Show CLI help.",
|
|
24
|
-
"name": "help",
|
|
25
|
-
"allowNo": false,
|
|
26
|
-
"type": "boolean"
|
|
27
|
-
},
|
|
28
|
-
"hidden": {
|
|
29
|
-
"description": "show hidden commands",
|
|
30
|
-
"name": "hidden",
|
|
31
|
-
"allowNo": false,
|
|
32
|
-
"type": "boolean"
|
|
33
|
-
},
|
|
34
|
-
"tree": {
|
|
35
|
-
"description": "show tree of commands",
|
|
36
|
-
"name": "tree",
|
|
37
|
-
"allowNo": false,
|
|
38
|
-
"type": "boolean"
|
|
39
|
-
},
|
|
40
15
|
"columns": {
|
|
41
|
-
"
|
|
16
|
+
"char": "c",
|
|
17
|
+
"description": "Only show provided columns (comma-separated).",
|
|
42
18
|
"exclusive": [
|
|
43
|
-
"
|
|
19
|
+
"tree"
|
|
44
20
|
],
|
|
45
21
|
"name": "columns",
|
|
22
|
+
"delimiter": ",",
|
|
46
23
|
"hasDynamicHelp": false,
|
|
47
|
-
"multiple":
|
|
24
|
+
"multiple": true,
|
|
25
|
+
"options": [
|
|
26
|
+
"id",
|
|
27
|
+
"plugin",
|
|
28
|
+
"summary",
|
|
29
|
+
"type"
|
|
30
|
+
],
|
|
48
31
|
"type": "option"
|
|
49
32
|
},
|
|
50
|
-
"
|
|
51
|
-
"description": "
|
|
52
|
-
"
|
|
53
|
-
"no-truncate"
|
|
54
|
-
],
|
|
55
|
-
"name": "csv",
|
|
33
|
+
"deprecated": {
|
|
34
|
+
"description": "Show deprecated commands.",
|
|
35
|
+
"name": "deprecated",
|
|
56
36
|
"allowNo": false,
|
|
57
37
|
"type": "boolean"
|
|
58
38
|
},
|
|
59
39
|
"extended": {
|
|
60
40
|
"char": "x",
|
|
61
|
-
"description": "
|
|
41
|
+
"description": "Show extra columns.",
|
|
62
42
|
"exclusive": [
|
|
63
|
-
"
|
|
43
|
+
"tree"
|
|
64
44
|
],
|
|
65
45
|
"name": "extended",
|
|
66
46
|
"allowNo": false,
|
|
67
47
|
"type": "boolean"
|
|
68
48
|
},
|
|
69
|
-
"
|
|
70
|
-
"description": "
|
|
71
|
-
"name": "
|
|
72
|
-
"hasDynamicHelp": false,
|
|
73
|
-
"multiple": false,
|
|
74
|
-
"type": "option"
|
|
75
|
-
},
|
|
76
|
-
"no-header": {
|
|
77
|
-
"description": "hide table header from output",
|
|
78
|
-
"exclusive": [
|
|
79
|
-
"csv"
|
|
80
|
-
],
|
|
81
|
-
"name": "no-header",
|
|
49
|
+
"hidden": {
|
|
50
|
+
"description": "Show hidden commands.",
|
|
51
|
+
"name": "hidden",
|
|
82
52
|
"allowNo": false,
|
|
83
53
|
"type": "boolean"
|
|
84
54
|
},
|
|
85
55
|
"no-truncate": {
|
|
86
|
-
"description": "
|
|
56
|
+
"description": "Do not truncate output.",
|
|
87
57
|
"exclusive": [
|
|
88
|
-
"
|
|
58
|
+
"tree"
|
|
89
59
|
],
|
|
90
60
|
"name": "no-truncate",
|
|
91
61
|
"allowNo": false,
|
|
92
62
|
"type": "boolean"
|
|
93
63
|
},
|
|
94
|
-
"
|
|
95
|
-
"description": "
|
|
64
|
+
"sort": {
|
|
65
|
+
"description": "Property to sort by.",
|
|
96
66
|
"exclusive": [
|
|
97
|
-
"
|
|
98
|
-
"csv"
|
|
67
|
+
"tree"
|
|
99
68
|
],
|
|
100
|
-
"name": "
|
|
69
|
+
"name": "sort",
|
|
70
|
+
"default": "id",
|
|
101
71
|
"hasDynamicHelp": false,
|
|
102
72
|
"multiple": false,
|
|
103
73
|
"options": [
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
74
|
+
"id",
|
|
75
|
+
"plugin",
|
|
76
|
+
"summary",
|
|
77
|
+
"type"
|
|
107
78
|
],
|
|
108
79
|
"type": "option"
|
|
109
80
|
},
|
|
110
|
-
"
|
|
111
|
-
"description": "
|
|
112
|
-
"name": "
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"type": "option"
|
|
81
|
+
"tree": {
|
|
82
|
+
"description": "Show tree of commands.",
|
|
83
|
+
"name": "tree",
|
|
84
|
+
"allowNo": false,
|
|
85
|
+
"type": "boolean"
|
|
116
86
|
}
|
|
117
87
|
},
|
|
118
88
|
"hasDynamicHelp": false,
|
|
@@ -135,5 +105,5 @@
|
|
|
135
105
|
]
|
|
136
106
|
}
|
|
137
107
|
},
|
|
138
|
-
"version": "
|
|
108
|
+
"version": "4.0.0"
|
|
139
109
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-commands",
|
|
3
3
|
"description": "plugin to show the list of all the commands",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-commands/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@oclif/core": "^
|
|
9
|
-
"lodash": "^4.17.21"
|
|
8
|
+
"@oclif/core": "^4.0.0-beta.13",
|
|
9
|
+
"lodash": "^4.17.21",
|
|
10
|
+
"object-treeify": "^4.0.1",
|
|
11
|
+
"tty-table": "^4.2.3"
|
|
10
12
|
},
|
|
11
13
|
"devDependencies": {
|
|
12
|
-
"@commitlint/config-conventional": "^
|
|
14
|
+
"@commitlint/config-conventional": "^19",
|
|
13
15
|
"@oclif/plugin-help": "^6",
|
|
14
16
|
"@oclif/prettier-config": "^0.2.1",
|
|
15
|
-
"@oclif/test": "^
|
|
17
|
+
"@oclif/test": "^4.0.2",
|
|
16
18
|
"@types/chai": "^4.3.11",
|
|
19
|
+
"@types/lodash": "^4.17.4",
|
|
17
20
|
"@types/mocha": "^10.0.6",
|
|
18
21
|
"@types/node": "^18",
|
|
22
|
+
"@types/sinon": "^17.0.3",
|
|
19
23
|
"chai": "^4.4.1",
|
|
20
|
-
"commitlint": "^
|
|
24
|
+
"commitlint": "^19",
|
|
21
25
|
"eslint": "^8.57.0",
|
|
22
26
|
"eslint-config-oclif": "^5.2.0",
|
|
23
27
|
"eslint-config-oclif-typescript": "^3.1.7",
|
|
@@ -26,9 +30,10 @@
|
|
|
26
30
|
"lint-staged": "^15",
|
|
27
31
|
"mocha": "^10.4.0",
|
|
28
32
|
"nyc": "^15.1.0",
|
|
29
|
-
"oclif": "^4.
|
|
33
|
+
"oclif": "^4.11.0",
|
|
30
34
|
"prettier": "^3.2.5",
|
|
31
35
|
"shx": "^0.3.3",
|
|
36
|
+
"sinon": "^18.0.0",
|
|
32
37
|
"ts-node": "^10.9.2",
|
|
33
38
|
"typescript": "^5.4.5"
|
|
34
39
|
},
|
package/lib/utils/tree.d.ts
DELETED
package/lib/utils/tree.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ux } from '@oclif/core';
|
|
2
|
-
const addNodes = (tree, commandParts) => {
|
|
3
|
-
const existingNode = tree.search(commandParts[0]);
|
|
4
|
-
// If the node exists and there's another part, add it to the node
|
|
5
|
-
if (existingNode && commandParts[1]) {
|
|
6
|
-
addNodes(existingNode, commandParts.slice(1));
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
// The node doesn't exist, create it
|
|
10
|
-
tree.insert(commandParts[0]);
|
|
11
|
-
// If there are more parts, add them to the node
|
|
12
|
-
if (commandParts.length > 1) {
|
|
13
|
-
addNodes(tree.search(commandParts[0]), commandParts.slice(1));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const createCommandTree = (commands, topicSeparator = ':') => {
|
|
18
|
-
const tree = ux.tree();
|
|
19
|
-
for (const command of commands) {
|
|
20
|
-
const commandParts = command.id.split(topicSeparator);
|
|
21
|
-
addNodes(tree, commandParts);
|
|
22
|
-
}
|
|
23
|
-
return tree;
|
|
24
|
-
};
|
|
25
|
-
export default createCommandTree;
|