@oclif/plugin-commands 4.0.16 → 4.1.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 +2 -2
- package/lib/commands/commands.js +22 -51
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
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/4.0
|
|
24
|
+
@oclif/plugin-commands/4.1.0 linux-x64 node-v20.17.0
|
|
25
25
|
$ oclif-example --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ oclif-example COMMAND
|
|
@@ -61,7 +61,7 @@ DESCRIPTION
|
|
|
61
61
|
List all oclif-example commands.
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v4.0
|
|
64
|
+
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v4.1.0/src/commands/commands.ts)_
|
|
65
65
|
<!-- commandsstop -->
|
|
66
66
|
|
|
67
67
|
# Contributing
|
package/lib/commands/commands.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Command, Flags, toConfiguredId } from '@oclif/core';
|
|
2
|
+
import { printTable } from '@oclif/table';
|
|
2
3
|
import _ from 'lodash';
|
|
3
4
|
// @ts-expect-error because object-treeify does not have types: https://github.com/blackflux/object-treeify/issues/1077
|
|
4
5
|
import treeify from 'object-treeify';
|
|
5
|
-
import TtyTable from 'tty-table';
|
|
6
6
|
const COLUMNS = ['id', 'plugin', 'summary', 'type'];
|
|
7
7
|
function createTree(commands) {
|
|
8
8
|
const tree = {};
|
|
@@ -16,20 +16,10 @@ function createTree(commands) {
|
|
|
16
16
|
}
|
|
17
17
|
return tree;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
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];
|
|
19
|
+
function mergePrototype(result, command) {
|
|
20
|
+
const proto = Object.getPrototypeOf(command);
|
|
21
|
+
const filteredProto = _.pickBy(proto, (v) => v !== undefined);
|
|
22
|
+
return Object.keys(proto).length > 0 ? mergePrototype({ ...filteredProto, ...result }, proto) : result;
|
|
33
23
|
}
|
|
34
24
|
export default class Commands extends Command {
|
|
35
25
|
static description = 'List all <%= config.bin %> commands.';
|
|
@@ -78,34 +68,22 @@ export default class Commands extends Command {
|
|
|
78
68
|
const tree = createTree(commands);
|
|
79
69
|
this.log(treeify(tree));
|
|
80
70
|
}
|
|
81
|
-
else {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
default: {
|
|
98
|
-
throw new Error('Unknown column');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
71
|
+
else if (!this.jsonEnabled()) {
|
|
72
|
+
printTable({
|
|
73
|
+
borderStyle: 'vertical-with-outline',
|
|
74
|
+
columns: (flags.columns ?? ['id', 'summary', ...(flags.extended ? ['plugin', 'type'] : [])]),
|
|
75
|
+
data: commands.map((c) => ({
|
|
76
|
+
id: toConfiguredId(c.id, config),
|
|
77
|
+
plugin: c.pluginName,
|
|
78
|
+
summary: c.summary ?? c.description,
|
|
79
|
+
type: c.pluginType,
|
|
80
|
+
})),
|
|
81
|
+
headerOptions: {
|
|
82
|
+
formatter: 'capitalCase',
|
|
83
|
+
},
|
|
84
|
+
overflow: flags['no-truncate'] ? 'wrap' : 'truncate',
|
|
85
|
+
sort: { [flags.sort]: 'asc' },
|
|
101
86
|
});
|
|
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());
|
|
109
87
|
}
|
|
110
88
|
const json = _.uniqBy(await Promise.all(commands.map(async (cmd) => {
|
|
111
89
|
let commandClass;
|
|
@@ -114,16 +92,9 @@ export default class Commands extends Command {
|
|
|
114
92
|
}
|
|
115
93
|
catch (error) {
|
|
116
94
|
this.debug(error);
|
|
95
|
+
return cmd;
|
|
117
96
|
}
|
|
118
|
-
const obj = { ...
|
|
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
|
-
}
|
|
97
|
+
const obj = { ...mergePrototype(commandClass, commandClass), ...cmd };
|
|
127
98
|
// The plugin property on the loaded class contains a LOT of information including all the commands again. Remove it.
|
|
128
99
|
delete obj.plugin;
|
|
129
100
|
// If Command classes have circular references, don't break the commands command.
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-commands",
|
|
3
3
|
"description": "plugin to show the list of all the commands",
|
|
4
|
-
"version": "4.0
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-commands/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@oclif/core": "^4",
|
|
9
|
+
"@oclif/table": "^0.1.12",
|
|
9
10
|
"lodash": "^4.17.21",
|
|
10
|
-
"object-treeify": "^4.0.1"
|
|
11
|
-
"tty-table": "^4.2.3"
|
|
11
|
+
"object-treeify": "^4.0.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@commitlint/config-conventional": "^19",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"lint-staged": "^15",
|
|
31
31
|
"mocha": "^10.7.3",
|
|
32
32
|
"nyc": "^15.1.0",
|
|
33
|
-
"oclif": "^4.14.
|
|
33
|
+
"oclif": "^4.14.35",
|
|
34
34
|
"prettier": "^3.3.3",
|
|
35
35
|
"shx": "^0.3.3",
|
|
36
36
|
"sinon": "^18.0.1",
|