@clerc/plugin-completions 1.0.0-beta.29 → 1.0.0-beta.30

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.
Files changed (2) hide show
  1. package/dist/index.js +5 -11
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,13 +1,7 @@
1
- import t from "@bomb.sh/tab";
1
+ import { RootCommand } from "@bomb.sh/tab";
2
2
  import { Types, definePlugin, extractParameterInfo, normalizeFlagValue, normalizeParameterValue } from "@clerc/core";
3
3
 
4
4
  //#region src/t.ts
5
- function resetTab() {
6
- t.commands.clear();
7
- t.options.clear();
8
- t.arguments.clear();
9
- t.completions = [];
10
- }
11
5
  function registerFlag(tc, flagName, def) {
12
6
  const normalized = normalizeFlagValue(def);
13
7
  const desc = normalized.description ?? "";
@@ -20,8 +14,7 @@ function registerFlag(tc, flagName, def) {
20
14
  function registerGlobalFlags(globalFlags, tc) {
21
15
  for (const [flagName, def] of Object.entries(globalFlags)) registerFlag(tc, flagName, def);
22
16
  }
23
- function buildTabModel(globalFlags, commands) {
24
- resetTab();
17
+ function buildTabModel(t, globalFlags, commands) {
25
18
  registerGlobalFlags(globalFlags, t);
26
19
  for (const cmd of commands.values()) {
27
20
  if (cmd.completions?.show === false) continue;
@@ -43,6 +36,7 @@ function buildTabModel(globalFlags, commands) {
43
36
  //#endregion
44
37
  //#region src/index.ts
45
38
  const completionsPlugin = () => definePlugin({ setup: (cli) => {
39
+ const t = new RootCommand();
46
40
  const supportedShellEnum = Types.Enum("zsh", "bash", "fish", "powershell");
47
41
  cli.command("completions", "Generate shell completion scripts", {
48
42
  flags: { shell: {
@@ -57,7 +51,7 @@ const completionsPlugin = () => definePlugin({ setup: (cli) => {
57
51
  }).on("completions", async (ctx) => {
58
52
  const shell = ctx.parameters.shell ?? ctx.flags.shell;
59
53
  if (!shell) throw new Error("Shell type is required. Please provide it via --shell flag or [shell] parameter.");
60
- buildTabModel(cli._globalFlags, cli._commands);
54
+ buildTabModel(t, cli._globalFlags, cli._commands);
61
55
  t.setup(cli._scriptName, cli._scriptName, shell);
62
56
  });
63
57
  cli.command("complete", {
@@ -65,7 +59,7 @@ const completionsPlugin = () => definePlugin({ setup: (cli) => {
65
59
  completions: { show: false },
66
60
  parameters: ["--", "[input...]"]
67
61
  }).on("complete", async (ctx) => {
68
- buildTabModel(cli._globalFlags, cli._commands);
62
+ buildTabModel(t, cli._globalFlags, cli._commands);
69
63
  const { input } = ctx.parameters;
70
64
  t.parse(input);
71
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-completions",
3
- "version": "1.0.0-beta.29",
3
+ "version": "1.0.0-beta.30",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc plugin completions",
@@ -51,8 +51,8 @@
51
51
  "@bomb.sh/tab": "^0.0.10"
52
52
  },
53
53
  "devDependencies": {
54
- "@clerc/core": "1.0.0-beta.29",
55
- "@clerc/utils": "1.0.0-beta.29"
54
+ "@clerc/core": "1.0.0-beta.30",
55
+ "@clerc/utils": "1.0.0-beta.30"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@clerc/core": "*"