@oclif/plugin-which 3.0.15 → 3.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 +6 -3
- package/lib/commands/which.d.ts +7 -1
- package/lib/commands/which.js +21 -12
- package/oclif.lock +1243 -982
- package/oclif.manifest.json +11 -3
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ $ npm install -g @oclif/plugin-which
|
|
|
22
22
|
$ oclif-example COMMAND
|
|
23
23
|
running command...
|
|
24
24
|
$ oclif-example (--version)
|
|
25
|
-
@oclif/plugin-which/3.0
|
|
25
|
+
@oclif/plugin-which/3.1.0 linux-x64 node-v20.11.0
|
|
26
26
|
$ oclif-example --help [COMMAND]
|
|
27
27
|
USAGE
|
|
28
28
|
$ oclif-example COMMAND
|
|
@@ -41,7 +41,10 @@ Show which plugin a command is in.
|
|
|
41
41
|
|
|
42
42
|
```
|
|
43
43
|
USAGE
|
|
44
|
-
$ oclif-example which
|
|
44
|
+
$ oclif-example which [--json]
|
|
45
|
+
|
|
46
|
+
GLOBAL FLAGS
|
|
47
|
+
--json Format output as json.
|
|
45
48
|
|
|
46
49
|
DESCRIPTION
|
|
47
50
|
Show which plugin a command is in.
|
|
@@ -52,5 +55,5 @@ EXAMPLES
|
|
|
52
55
|
$ oclif-example which help
|
|
53
56
|
```
|
|
54
57
|
|
|
55
|
-
_See code: [src/commands/which.ts](https://github.com/oclif/plugin-which/blob/v3.0
|
|
58
|
+
_See code: [src/commands/which.ts](https://github.com/oclif/plugin-which/blob/v3.1.0/src/commands/which.ts)_
|
|
56
59
|
<!-- commandsstop -->
|
package/lib/commands/which.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { Command } from '@oclif/core';
|
|
2
|
+
type WhichResult = {
|
|
3
|
+
aliasOf?: string;
|
|
4
|
+
plugin: string;
|
|
5
|
+
};
|
|
2
6
|
export default class Which extends Command {
|
|
3
7
|
static description: string;
|
|
8
|
+
static enableJsonFlag: boolean;
|
|
4
9
|
static examples: {
|
|
5
10
|
command: string;
|
|
6
11
|
description: string;
|
|
7
12
|
}[];
|
|
8
13
|
static strict: boolean;
|
|
9
|
-
run(): Promise<
|
|
14
|
+
run(): Promise<WhichResult>;
|
|
10
15
|
}
|
|
16
|
+
export {};
|
package/lib/commands/which.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Command, ux } from '@oclif/core';
|
|
1
|
+
import { Command, Errors, toConfiguredId, ux } from '@oclif/core';
|
|
2
2
|
export default class Which extends Command {
|
|
3
3
|
static description = 'Show which plugin a command is in.';
|
|
4
|
+
static enableJsonFlag = true;
|
|
4
5
|
static examples = [
|
|
5
6
|
{
|
|
6
7
|
command: '<%= config.bin %> <%= command.id %> help',
|
|
@@ -11,18 +12,26 @@ export default class Which extends Command {
|
|
|
11
12
|
async run() {
|
|
12
13
|
const { argv } = await this.parse(Which);
|
|
13
14
|
if (argv.length === 0) {
|
|
14
|
-
throw new
|
|
15
|
+
throw new Errors.CLIError('"which" expects a command name', {
|
|
16
|
+
suggestions: [`Provide a command id like this, "${this.config.bin} which your:command:here"`],
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// if argv is length 1 and is a string, split it by the topicSeparator (e.g. "my:command" => ["my", "command"], "my command" => ["my", "command"])
|
|
20
|
+
// otherwise, use argv as is (e.g. ["my", "command"] => ["my", "command"])
|
|
21
|
+
const commandParts = argv.length === 1 && typeof argv[0] === 'string' ? argv[0].split(this.config.topicSeparator) : argv;
|
|
22
|
+
const cmd = this.config.findCommand(commandParts.join(':'), { must: true });
|
|
23
|
+
const isAlias = cmd.aliases.includes(commandParts.join(':'));
|
|
24
|
+
const result = { plugin: cmd.pluginName ?? 'unknown' };
|
|
25
|
+
if (isAlias) {
|
|
26
|
+
const possible = this.config.commands.find((c) => c.aliases.includes(cmd.id) && c.id !== cmd.id);
|
|
27
|
+
if (possible) {
|
|
28
|
+
result.aliasOf = toConfiguredId(possible?.id, this.config);
|
|
29
|
+
}
|
|
21
30
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
if (!this.jsonEnabled()) {
|
|
32
|
+
ux.styledHeader(commandParts.join(this.config.topicSeparator));
|
|
33
|
+
ux.styledObject(result);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
27
36
|
}
|
|
28
37
|
}
|