@oclif/plugin-commands 1.2.3 → 1.3.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 +13 -5
- package/lib/commands/commands.d.ts +4 -6
- package/lib/commands/commands.js +84 -11
- package/oclif.manifest.json +1 -1
- package/package.json +13 -10
- package/yarn.lock +943 -213
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 (-v|--version|version)
|
|
24
|
-
@oclif/plugin-commands/1.
|
|
24
|
+
@oclif/plugin-commands/1.3.0 darwin-x64 node-v12.16.1
|
|
25
25
|
$ oclif-example --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ oclif-example COMMAND
|
|
@@ -41,10 +41,18 @@ USAGE
|
|
|
41
41
|
$ oclif-example commands
|
|
42
42
|
|
|
43
43
|
OPTIONS
|
|
44
|
-
-h, --help
|
|
45
|
-
-j, --json
|
|
46
|
-
--
|
|
44
|
+
-h, --help show CLI help
|
|
45
|
+
-j, --json display unfiltered api data in json format
|
|
46
|
+
-x, --extended show extra columns
|
|
47
|
+
--columns=columns only show provided columns (comma-separated)
|
|
48
|
+
--csv output is csv format [alias: --output=csv]
|
|
49
|
+
--filter=filter filter property by partial string matching, ex: name=foo
|
|
50
|
+
--hidden show hidden commands
|
|
51
|
+
--no-header hide table header from output
|
|
52
|
+
--no-truncate do not truncate output to fit screen
|
|
53
|
+
--output=csv|json|yaml output in a more machine friendly format
|
|
54
|
+
--sort=sort property to sort by (prepend '-' for descending)
|
|
47
55
|
```
|
|
48
56
|
|
|
49
|
-
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v1.
|
|
57
|
+
_See code: [src/commands/commands.ts](https://github.com/oclif/plugin-commands/blob/v1.3.0/src/commands/commands.ts)_
|
|
50
58
|
<!-- commandsstop -->
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { Command } from '@oclif/command';
|
|
1
|
+
import { Command, flags } from '@oclif/command';
|
|
2
2
|
export default class Commands extends Command {
|
|
3
3
|
static description: string;
|
|
4
|
-
static flags:
|
|
5
|
-
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
6
|
-
json: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
7
|
-
hidden: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
8
|
-
};
|
|
4
|
+
static flags: flags.Input<any>;
|
|
9
5
|
run(): Promise<void>;
|
|
6
|
+
private getCommands;
|
|
7
|
+
private removeCycles;
|
|
10
8
|
}
|
package/lib/commands/commands.js
CHANGED
|
@@ -3,28 +3,101 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const command_1 = require("@oclif/command");
|
|
4
4
|
const cli_ux_1 = require("cli-ux");
|
|
5
5
|
const _ = require("lodash");
|
|
6
|
+
const os_1 = require("os");
|
|
6
7
|
class Commands extends command_1.Command {
|
|
7
8
|
async run() {
|
|
8
9
|
const { flags } = this.parse(Commands);
|
|
9
|
-
let commands = this.
|
|
10
|
+
let commands = this.getCommands();
|
|
10
11
|
if (!flags.hidden) {
|
|
11
12
|
commands = commands.filter(c => !c.hidden);
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
const config = this.config;
|
|
15
|
+
commands = _.sortBy(commands, 'id').map(command => {
|
|
16
|
+
// Template supported fields.
|
|
17
|
+
command.description = (typeof command.description === 'string' && _.template(command.description)({ command, config })) || undefined;
|
|
18
|
+
command.usage = (typeof command.usage === 'string' && _.template(command.usage)({ command, config })) || undefined;
|
|
19
|
+
return command;
|
|
20
|
+
});
|
|
14
21
|
if (flags.json) {
|
|
15
|
-
cli_ux_1.
|
|
22
|
+
cli_ux_1.ux.styledJSON(commands.map(cmd => {
|
|
23
|
+
let commandClass = cmd.load();
|
|
24
|
+
const obj = Object.assign({}, cmd, commandClass);
|
|
25
|
+
// Load all properties on all extending classes.
|
|
26
|
+
while (commandClass !== undefined) {
|
|
27
|
+
commandClass = Object.getPrototypeOf(commandClass) || undefined;
|
|
28
|
+
Object.assign(obj, commandClass);
|
|
29
|
+
}
|
|
30
|
+
// The plugin property on the loaded class contains a LOT of information including all the commands again. Remove it.
|
|
31
|
+
delete obj.plugin;
|
|
32
|
+
// If Command classes have circular references, don't break the commands command.
|
|
33
|
+
return this.removeCycles(obj);
|
|
34
|
+
}));
|
|
16
35
|
}
|
|
17
36
|
else {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
cli_ux_1.ux.table(commands.map(command => {
|
|
38
|
+
// Massage some fields so it looks good in the table
|
|
39
|
+
command.description = (command.description || '').split(os_1.EOL)[0];
|
|
40
|
+
command.hidden = Boolean(command.hidden);
|
|
41
|
+
command.usage = (command.usage || '');
|
|
42
|
+
return command;
|
|
43
|
+
}), {
|
|
44
|
+
id: {
|
|
45
|
+
header: 'Command',
|
|
46
|
+
},
|
|
47
|
+
description: {},
|
|
48
|
+
usage: {
|
|
49
|
+
extended: true,
|
|
50
|
+
},
|
|
51
|
+
pluginName: {
|
|
52
|
+
extended: true,
|
|
53
|
+
header: 'Plugin',
|
|
54
|
+
},
|
|
55
|
+
pluginType: {
|
|
56
|
+
extended: true,
|
|
57
|
+
header: 'Type',
|
|
58
|
+
},
|
|
59
|
+
hidden: {
|
|
60
|
+
extended: true,
|
|
61
|
+
},
|
|
62
|
+
}, Object.assign({ printLine: this.log }, flags));
|
|
21
63
|
}
|
|
22
64
|
}
|
|
65
|
+
getCommands() {
|
|
66
|
+
return this.config.commands;
|
|
67
|
+
}
|
|
68
|
+
removeCycles(object) {
|
|
69
|
+
// Keep track of seen objects.
|
|
70
|
+
const seenObjects = new WeakMap();
|
|
71
|
+
const _removeCycles = (obj) => {
|
|
72
|
+
// Use object prototype to get around type and null checks
|
|
73
|
+
if (Object.prototype.toString.call(obj) === '[object Object]') {
|
|
74
|
+
// We know it is a "Dictionary" because of the conditional
|
|
75
|
+
const dictionary = obj;
|
|
76
|
+
if (seenObjects.has(dictionary)) {
|
|
77
|
+
// Seen, return undefined to remove.
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
seenObjects.set(dictionary, undefined);
|
|
81
|
+
for (const key in dictionary) {
|
|
82
|
+
// Delete the duplicate object if cycle found.
|
|
83
|
+
if (_removeCycles(dictionary[key]) === undefined) {
|
|
84
|
+
delete dictionary[key];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (Array.isArray(obj)) {
|
|
89
|
+
for (const i in obj) {
|
|
90
|
+
if (_removeCycles(obj[i]) === undefined) {
|
|
91
|
+
// We don't want to delete the array, but we can replace the element with null.
|
|
92
|
+
obj[i] = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return obj;
|
|
97
|
+
};
|
|
98
|
+
return _removeCycles(object);
|
|
99
|
+
}
|
|
23
100
|
}
|
|
24
101
|
Commands.description = 'list all the commands';
|
|
25
|
-
Commands.flags = {
|
|
26
|
-
help: command_1.flags.help({ char: 'h' }),
|
|
27
|
-
json: command_1.flags.boolean({ char: 'j', description: 'output in json format' }),
|
|
28
|
-
hidden: command_1.flags.boolean({ description: 'also show hidden commands' }),
|
|
29
|
-
};
|
|
102
|
+
Commands.flags = Object.assign({ help: command_1.flags.help({ char: 'h' }), json: command_1.flags.boolean({ char: 'j', description: 'display unfiltered api data in json format' }), hidden: command_1.flags.boolean({ description: 'show hidden commands' }) }, cli_ux_1.ux.table.flags());
|
|
30
103
|
exports.default = Commands;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.
|
|
1
|
+
{"version":"1.3.0","commands":{"commands":{"id":"commands","description":"list all the commands","pluginName":"@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)"},"sort":{"name":"sort","type":"option","description":"property to sort by (prepend '-' for descending)"},"filter":{"name":"filter","type":"option","description":"filter property by partial string matching, ex: name=foo"},"csv":{"name":"csv","type":"boolean","description":"output is csv format [alias: --output=csv]","allowNo":false},"output":{"name":"output","type":"option","description":"output in a more machine friendly format","options":["csv","json","yaml"]},"extended":{"name":"extended","type":"boolean","char":"x","description":"show extra columns","allowNo":false},"no-truncate":{"name":"no-truncate","type":"boolean","description":"do not truncate output to fit screen","allowNo":false},"no-header":{"name":"no-header","type":"boolean","description":"hide table header from output","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-commands",
|
|
3
3
|
"description": "plugin to show the list of all the commands",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"author": "Jeff Dickey @jdxcode",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-commands/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@oclif/command": "^1.5.4",
|
|
9
9
|
"@oclif/config": "^1.8.7",
|
|
10
|
-
"cli-ux": "^4.
|
|
11
|
-
"lodash": "^4.17.11"
|
|
12
|
-
"tslib": "^1.9.3"
|
|
10
|
+
"cli-ux": "^5.4.5",
|
|
11
|
+
"lodash": "^4.17.11"
|
|
13
12
|
},
|
|
14
13
|
"devDependencies": {
|
|
15
14
|
"@oclif/dev-cli": "^1.19.1",
|
|
16
15
|
"@oclif/plugin-help": "^2.1.2",
|
|
17
16
|
"@oclif/test": "^1.2.1",
|
|
18
|
-
"@oclif/tslint": "^3.1.0",
|
|
19
17
|
"@types/chai": "^4.1.6",
|
|
20
18
|
"@types/lodash": "^4.14.117",
|
|
21
19
|
"@types/mocha": "^5.2.5",
|
|
22
|
-
"@types/node": "^10.
|
|
20
|
+
"@types/node": "^8.10.59",
|
|
23
21
|
"chai": "^4.2.0",
|
|
22
|
+
"eslint": "^6.6.0",
|
|
23
|
+
"eslint-config-oclif": "^3.1.0",
|
|
24
|
+
"eslint-config-oclif-typescript": "^0.1.0",
|
|
24
25
|
"globby": "^8",
|
|
25
26
|
"mocha": "^5",
|
|
26
27
|
"nyc": "^13.0.1",
|
|
27
28
|
"ts-node": "^7.0.1",
|
|
28
|
-
"
|
|
29
|
+
"tslib": "^1.9.3",
|
|
29
30
|
"typescript": "^3.1.3"
|
|
30
31
|
},
|
|
31
32
|
"engines": {
|
|
@@ -50,10 +51,12 @@
|
|
|
50
51
|
},
|
|
51
52
|
"repository": "oclif/plugin-commands",
|
|
52
53
|
"scripts": {
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"prepack": "rm -rf lib && tsc && oclif-dev manifest && oclif-dev readme",
|
|
54
|
+
"lint": "eslint ./src ./test --ext .ts --config .eslintrc",
|
|
55
|
+
"pretest": "tsc -p test --noEmit",
|
|
56
56
|
"test": "nyc mocha --forbid-only \"test/**/*.test.ts\"",
|
|
57
|
+
"posttest": "yarn lint",
|
|
58
|
+
"prepack": "rm -rf lib && tsc && oclif-dev manifest && oclif-dev readme",
|
|
59
|
+
"postpack": "rm -f oclif.manifest.json",
|
|
57
60
|
"version": "oclif-dev readme && git add README.md"
|
|
58
61
|
}
|
|
59
62
|
}
|