@clerc/plugin-completions 1.0.0-beta.16 → 1.0.0-beta.18
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/dist/index.js +25 -14
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOUBLE_DASH, definePlugin, resolveCommand } from "@clerc/core";
|
|
1
|
+
import { DOUBLE_DASH, Types, definePlugin, normalizeFlagValue, resolveCommand } from "@clerc/core";
|
|
2
2
|
import tabtab, { getShellFromEnv } from "@pnpm/tabtab";
|
|
3
3
|
|
|
4
4
|
//#region ../utils/src/index.ts
|
|
@@ -47,15 +47,16 @@ async function getCompletion(cli, env) {
|
|
|
47
47
|
} : cli._globalFlags;
|
|
48
48
|
const candidates$1 = [];
|
|
49
49
|
for (const [name, def] of Object.entries(flags)) {
|
|
50
|
+
const normalized = normalizeFlagValue(def);
|
|
50
51
|
candidates$1.push({
|
|
51
52
|
name: formatFlagName(name),
|
|
52
|
-
description:
|
|
53
|
+
description: normalized.description
|
|
53
54
|
});
|
|
54
|
-
if (
|
|
55
|
-
const aliases = toArray(
|
|
55
|
+
if (normalized.alias) {
|
|
56
|
+
const aliases = toArray(normalized.alias);
|
|
56
57
|
for (const alias of aliases) candidates$1.push({
|
|
57
58
|
name: formatFlagName(alias),
|
|
58
|
-
description:
|
|
59
|
+
description: normalized.description
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -87,42 +88,52 @@ async function getCompletion(cli, env) {
|
|
|
87
88
|
//#region src/index.ts
|
|
88
89
|
const completionsPlugin = (options = {}) => definePlugin({ setup: (cli) => {
|
|
89
90
|
const { managementCommands = true } = options;
|
|
91
|
+
cli.store.help?.addGroup({ commands: [["completions", "Completions"]] });
|
|
92
|
+
const supportedShellEnum = Types.Enum(...tabtab.SUPPORTED_SHELLS);
|
|
90
93
|
if (managementCommands) {
|
|
91
94
|
cli.command("completions install", "Install shell completions", {
|
|
92
95
|
help: { group: "completions" },
|
|
93
96
|
flags: { shell: {
|
|
94
97
|
description: "Shell type",
|
|
95
|
-
type:
|
|
98
|
+
type: supportedShellEnum
|
|
96
99
|
} },
|
|
97
|
-
parameters: [
|
|
100
|
+
parameters: [{
|
|
101
|
+
key: "[shell]",
|
|
102
|
+
description: "Shell type",
|
|
103
|
+
type: supportedShellEnum
|
|
104
|
+
}]
|
|
98
105
|
}).on("completions install", async (ctx) => {
|
|
99
106
|
const shell = ctx.parameters.shell ?? ctx.flags.shell;
|
|
100
107
|
if (!shell) throw new Error("Please specify the shell type via the --shell flag or the [shell] parameter.");
|
|
101
108
|
if (!tabtab.SUPPORTED_SHELLS.includes(shell)) throw new Error(`Unsupported shell: ${shell}. Supported shells are: ${tabtab.SUPPORTED_SHELLS.join(", ")}.`);
|
|
102
109
|
await tabtab.install({
|
|
103
|
-
name: cli.
|
|
104
|
-
completer: cli.
|
|
110
|
+
name: cli._scriptName,
|
|
111
|
+
completer: cli._scriptName,
|
|
105
112
|
shell
|
|
106
113
|
});
|
|
107
114
|
});
|
|
108
115
|
cli.command("completions uninstall", "Uninstall shell completions", { help: { group: "completions" } }).on("completions uninstall", async () => {
|
|
109
|
-
await tabtab.uninstall({ name: cli.
|
|
116
|
+
await tabtab.uninstall({ name: cli._scriptName });
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
119
|
cli.command("completions", "Generate completions script", {
|
|
113
120
|
help: { group: "completions" },
|
|
114
121
|
flags: { shell: {
|
|
115
122
|
description: "Shell type",
|
|
116
|
-
type:
|
|
123
|
+
type: supportedShellEnum
|
|
117
124
|
} },
|
|
118
|
-
parameters: [
|
|
125
|
+
parameters: [{
|
|
126
|
+
key: "[shell]",
|
|
127
|
+
description: "Shell type",
|
|
128
|
+
type: supportedShellEnum
|
|
129
|
+
}]
|
|
119
130
|
}).on("completions", async (ctx) => {
|
|
120
131
|
const shell = ctx.parameters.shell ?? ctx.flags.shell;
|
|
121
132
|
if (!shell) throw new Error("Please specify the shell type via the --shell flag or the [shell] parameter.");
|
|
122
133
|
if (!tabtab.SUPPORTED_SHELLS.includes(shell)) throw new Error(`Unsupported shell: ${shell}. Supported shells are: ${tabtab.SUPPORTED_SHELLS.join(", ")}.`);
|
|
123
134
|
const script = await tabtab.getCompletionScript({
|
|
124
|
-
name: cli.
|
|
125
|
-
completer: cli.
|
|
135
|
+
name: cli._scriptName,
|
|
136
|
+
completer: cli._scriptName,
|
|
126
137
|
shell
|
|
127
138
|
});
|
|
128
139
|
console.log(script);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-completions",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc plugin completions",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"@pnpm/tabtab": "^0.5.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@clerc/
|
|
52
|
-
"@clerc/
|
|
51
|
+
"@clerc/core": "1.0.0-beta.18",
|
|
52
|
+
"@clerc/utils": "1.0.0-beta.18"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@clerc/core": "*"
|