politty 0.4.3 → 0.4.6

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 (60) hide show
  1. package/dist/{arg-registry-BUUhZ7JR.d.ts → arg-registry-2m40k1Et.d.ts} +1 -1
  2. package/dist/{arg-registry-BUUhZ7JR.d.ts.map → arg-registry-2m40k1Et.d.ts.map} +1 -1
  3. package/dist/augment.d.ts +1 -1
  4. package/dist/completion/index.cjs +16 -168
  5. package/dist/completion/index.d.cts +2 -77
  6. package/dist/completion/index.d.ts +2 -77
  7. package/dist/completion/index.js +3 -154
  8. package/dist/{zsh-CASZWn0o.cjs → completion-Df0eZ70u.cjs} +326 -37
  9. package/dist/completion-Df0eZ70u.cjs.map +1 -0
  10. package/dist/{zsh-hjvdI8uZ.js → completion-_AnQsWh9.js} +298 -27
  11. package/dist/completion-_AnQsWh9.js.map +1 -0
  12. package/dist/docs/index.cjs +276 -29
  13. package/dist/docs/index.cjs.map +1 -1
  14. package/dist/docs/index.d.cts +62 -7
  15. package/dist/docs/index.d.cts.map +1 -1
  16. package/dist/docs/index.d.ts +62 -7
  17. package/dist/docs/index.d.ts.map +1 -1
  18. package/dist/docs/index.js +271 -30
  19. package/dist/docs/index.js.map +1 -1
  20. package/dist/{value-completion-resolver-BQgHsX7b.d.cts → index-BZalbMeu.d.ts} +83 -4
  21. package/dist/index-BZalbMeu.d.ts.map +1 -0
  22. package/dist/{value-completion-resolver-C9LTGr0O.d.ts → index-C5-0RXiH.d.cts} +83 -4
  23. package/dist/index-C5-0RXiH.d.cts.map +1 -0
  24. package/dist/index.cjs +8 -7
  25. package/dist/index.d.cts +67 -13
  26. package/dist/index.d.cts.map +1 -1
  27. package/dist/index.d.ts +68 -14
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +4 -5
  30. package/dist/{lazy-BEDnSR0m.cjs → lazy-DHlvJiQQ.cjs} +44 -8
  31. package/dist/lazy-DHlvJiQQ.cjs.map +1 -0
  32. package/dist/{lazy-BrEg8SgI.js → lazy-DSyfzR-F.js} +38 -8
  33. package/dist/lazy-DSyfzR-F.js.map +1 -0
  34. package/dist/{runner-C4fSHJMe.cjs → runner-C1Aah5c5.cjs} +365 -23
  35. package/dist/runner-C1Aah5c5.cjs.map +1 -0
  36. package/dist/{runner-D6k4BgB4.js → runner-DjG0uBxQ.js} +365 -23
  37. package/dist/runner-DjG0uBxQ.js.map +1 -0
  38. package/dist/{schema-extractor-n9288WJ6.d.ts → schema-extractor-C9APqeSL.d.ts} +30 -3
  39. package/dist/schema-extractor-C9APqeSL.d.ts.map +1 -0
  40. package/dist/{schema-extractor-DFaAZzaY.d.cts → schema-extractor-CVf0J4An.d.cts} +29 -2
  41. package/dist/schema-extractor-CVf0J4An.d.cts.map +1 -0
  42. package/dist/{subcommand-router-CAzBsLSI.js → subcommand-router-CKuy6D2b.js} +2 -2
  43. package/dist/{subcommand-router-CAzBsLSI.js.map → subcommand-router-CKuy6D2b.js.map} +1 -1
  44. package/dist/{subcommand-router-ZjNjFaUL.cjs → subcommand-router-sZHhUP7b.cjs} +2 -2
  45. package/dist/{subcommand-router-ZjNjFaUL.cjs.map → subcommand-router-sZHhUP7b.cjs.map} +1 -1
  46. package/package.json +9 -9
  47. package/dist/completion/index.cjs.map +0 -1
  48. package/dist/completion/index.d.cts.map +0 -1
  49. package/dist/completion/index.d.ts.map +0 -1
  50. package/dist/completion/index.js.map +0 -1
  51. package/dist/lazy-BEDnSR0m.cjs.map +0 -1
  52. package/dist/lazy-BrEg8SgI.js.map +0 -1
  53. package/dist/runner-C4fSHJMe.cjs.map +0 -1
  54. package/dist/runner-D6k4BgB4.js.map +0 -1
  55. package/dist/schema-extractor-DFaAZzaY.d.cts.map +0 -1
  56. package/dist/schema-extractor-n9288WJ6.d.ts.map +0 -1
  57. package/dist/value-completion-resolver-BQgHsX7b.d.cts.map +0 -1
  58. package/dist/value-completion-resolver-C9LTGr0O.d.ts.map +0 -1
  59. package/dist/zsh-CASZWn0o.cjs.map +0 -1
  60. package/dist/zsh-hjvdI8uZ.js.map +0 -1
@@ -141,4 +141,4 @@ declare function arg<T extends z.ZodType>(schema: T): T;
141
141
  declare function arg<T extends z.ZodType, M extends ArgMeta>(schema: T, meta: ValidateArgMeta<M>): T;
142
142
  //#endregion
143
143
  export { arg as a, CustomCompletion as i, CompletionMeta as n, CompletionType as r, ArgMeta as t };
144
- //# sourceMappingURL=arg-registry-BUUhZ7JR.d.ts.map
144
+ //# sourceMappingURL=arg-registry-2m40k1Et.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"arg-registry-BUUhZ7JR.d.ts","names":[],"sources":["../src/core/arg-registry.ts"],"mappings":";;;;;AAKA;KAAY,cAAA;;;;UAKK,gBAAA;EAAgB;EAE/B,OAAA;EAAA;EAEA,YAAA;AAAA;;;;;;;;;;;;;;AAqDF;;;;;;;;;;;;AA6BA;;;;;AAQA;KAxDY,cAAA;iCAEV,IAAA,GAAO,cAAA,EAsDuC;EApD9C,MAAA,GAAS,gBAAA;AAAA;EAwDW,+DArDgD,UAAA;EAChE,OAAA;AAAA;EA0Da,yEAvD6D,OAAA;EAC1E,UAAA;AAAA;;AA4D2C;;UArDhC,WAAA;EAkFS;EAhFxB,WAAA;EAkFI;EAhFJ,UAAA;EAkFsB;EAhFtB,WAAA;EAoFE;;;;;;;;;;;;;;EArEF,GAAA;EAqEG;EAnEH,UAAA,GAAa,cAAA;AAAA;;;;UAME,cAAA,SAAuB,WAAA;EA+Da;EA7DnD,KAAA;AAAA;;;;UAMe,sBAAA,SAA+B,WAAA;EAuDP;EArDvC,KAAA;EAqDoD;EAnDpD,oBAAA;AAAA;;;;KAMU,OAAA,GAAU,cAAA,GAAiB,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmClC,eAAA,MAAqB,CAAA;EAAY,KAAA;AAAA,IAClC,CAAA;EAAY,oBAAA;AAAA,IACV,CAAA,iBAEc,CAAA,GAAI,CAAA,CAAE,CAAA;EAElB,WAAA;AAAA,IAEJ,CAAA;AAAA,iBAEY,GAAA,WAAc,CAAA,CAAE,OAAA,CAAA,CAAS,MAAA,EAAQ,CAAA,GAAI,CAAA;AAAA,iBACrC,GAAA,WAAc,CAAA,CAAE,OAAA,YAAmB,OAAA,CAAA,CAAS,MAAA,EAAQ,CAAA,EAAG,IAAA,EAAM,eAAA,CAAgB,CAAA,IAAK,CAAA"}
1
+ {"version":3,"file":"arg-registry-2m40k1Et.d.ts","names":[],"sources":["../src/core/arg-registry.ts"],"mappings":";;;;;AAKA;KAAY,cAAA;;;;UAKK,gBAAA;EAAgB;EAE/B,OAAA;EAAA;EAEA,YAAA;AAAA;;;;;;;;;;;;;;AAqDF;;;;;;;;;;;;AA6BA;;;;;AAQA;KAxDY,cAAA;iCAEV,IAAA,GAAO,cAAA,EAsDuC;EApD9C,MAAA,GAAS,gBAAA;AAAA;EAwDW,+DArDgD,UAAA;EAChE,OAAA;AAAA;EA0Da,yEAvD6D,OAAA;EAC1E,UAAA;AAAA;;AA4D2C;;UArDhC,WAAA;EAkFS;EAhFxB,WAAA;EAkFI;EAhFJ,UAAA;EAkFsB;EAhFtB,WAAA;EAoFE;;;;;;;;;;;;;;EArEF,GAAA;EAqEG;EAnEH,UAAA,GAAa,cAAA;AAAA;;;;UAME,cAAA,SAAuB,WAAA;EA+Da;EA7DnD,KAAA;AAAA;;;;UAMe,sBAAA,SAA+B,WAAA;EAuDP;EArDvC,KAAA;EAqDoD;EAnDpD,oBAAA;AAAA;;;;KAMU,OAAA,GAAU,cAAA,GAAiB,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmClC,eAAA,MAAqB,CAAA;EAAY,KAAA;AAAA,IAClC,CAAA;EAAY,oBAAA;AAAA,IACV,CAAA,iBAEc,CAAA,GAAI,CAAA,CAAE,CAAA;EAElB,WAAA;AAAA,IAEJ,CAAA;AAAA,iBAEY,GAAA,WAAc,CAAA,CAAE,OAAA,CAAA,CAAS,MAAA,EAAQ,CAAA,GAAI,CAAA;AAAA,iBACrC,GAAA,WAAc,CAAA,CAAE,OAAA,YAAmB,OAAA,CAAA,CAAS,MAAA,EAAQ,CAAA,EAAG,IAAA,EAAM,eAAA,CAAgB,CAAA,IAAK,CAAA"}
package/dist/augment.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ArgMeta } from "./arg-registry-BUUhZ7JR.js";
1
+ import { t as ArgMeta } from "./arg-registry-2m40k1Et.js";
2
2
 
3
3
  //#region src/augment.d.ts
4
4
  declare module "zod" {
@@ -1,170 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_subcommand_router = require('../subcommand-router-ZjNjFaUL.cjs');
3
- const require_lazy = require('../lazy-BEDnSR0m.cjs');
4
- const require_zsh = require('../zsh-CASZWn0o.cjs');
5
- let zod = require("zod");
2
+ require('../lazy-DHlvJiQQ.cjs');
3
+ const require_completion = require('../completion-Df0eZ70u.cjs');
6
4
 
7
- //#region src/completion/index.ts
8
- /**
9
- * Shell completion generation module
10
- *
11
- * Provides utilities to generate shell completion scripts for bash, zsh, and fish.
12
- *
13
- * @example
14
- * ```typescript
15
- * import { generateCompletion, createCompletionCommand } from "politty/completion";
16
- *
17
- * // Generate completion script directly
18
- * const result = generateCompletion(myCommand, {
19
- * shell: "bash",
20
- * programName: "mycli"
21
- * });
22
- * console.log(result.script);
23
- *
24
- * // Or add a completion subcommand to your CLI
25
- * const mainCommand = withCompletionCommand(
26
- * defineCommand({
27
- * name: "mycli",
28
- * subCommands: { ... },
29
- * }),
30
- * );
31
- * ```
32
- */
33
- /**
34
- * Generate completion script for the specified shell
35
- */
36
- function generateCompletion(command, options) {
37
- switch (options.shell) {
38
- case "bash": return require_zsh.generateBashCompletion(command, options);
39
- case "zsh": return require_zsh.generateZshCompletion(command, options);
40
- case "fish": return require_zsh.generateFishCompletion(command, options);
41
- default: throw new Error(`Unsupported shell: ${options.shell}`);
42
- }
43
- }
44
- /**
45
- * Get the list of supported shells
46
- */
47
- function getSupportedShells() {
48
- return [
49
- "bash",
50
- "zsh",
51
- "fish"
52
- ];
53
- }
54
- /**
55
- * Detect the current shell from environment
56
- */
57
- function detectShell() {
58
- const shellName = (process.env.SHELL || "").split("/").pop()?.toLowerCase() || "";
59
- if (shellName.includes("bash")) return "bash";
60
- if (shellName.includes("zsh")) return "zsh";
61
- if (shellName.includes("fish")) return "fish";
62
- return null;
63
- }
64
- /**
65
- * Schema for the completion command arguments
66
- */
67
- const completionArgsSchema = zod.z.object({
68
- shell: require_lazy.arg(zod.z.enum([
69
- "bash",
70
- "zsh",
71
- "fish"
72
- ]).optional().describe("Shell type (auto-detected if not specified)"), {
73
- positional: true,
74
- description: "Shell type (bash, zsh, or fish)",
75
- placeholder: "SHELL"
76
- }),
77
- instructions: require_lazy.arg(zod.z.boolean().default(false), {
78
- alias: "i",
79
- description: "Show installation instructions"
80
- })
81
- });
82
- /**
83
- * Create a completion subcommand for your CLI
84
- *
85
- * This creates a ready-to-use subcommand that generates completion scripts.
86
- *
87
- * @example
88
- * ```typescript
89
- * const mainCommand = defineCommand({
90
- * name: "mycli",
91
- * subCommands: {
92
- * completion: createCompletionCommand(mainCommand)
93
- * }
94
- * });
95
- * ```
96
- */
97
- function createCompletionCommand(rootCommand, programName) {
98
- const resolvedProgramName = programName ?? rootCommand.name;
99
- if (!rootCommand.subCommands?.__complete) rootCommand.subCommands = {
100
- ...rootCommand.subCommands,
101
- __complete: require_zsh.createDynamicCompleteCommand(rootCommand, resolvedProgramName)
102
- };
103
- return require_zsh.defineCommand({
104
- name: "completion",
105
- description: "Generate shell completion script",
106
- args: completionArgsSchema,
107
- run(args) {
108
- const shellType = args.shell || detectShell();
109
- if (!shellType) {
110
- console.error("Could not detect shell type. Please specify one of: bash, zsh, fish");
111
- process.exitCode = 1;
112
- return;
113
- }
114
- const result = generateCompletion(rootCommand, {
115
- shell: shellType,
116
- programName: resolvedProgramName,
117
- includeDescriptions: true
118
- });
119
- if (args.instructions) console.log(result.installInstructions);
120
- else console.log(result.script);
121
- }
122
- });
123
- }
124
- /**
125
- * Wrap a command with a completion subcommand
126
- *
127
- * This avoids circular references that occur when a command references itself
128
- * in its subCommands (e.g., for completion generation).
129
- *
130
- * @param command - The command to wrap
131
- * @param options - Options including programName
132
- * @returns A new command with the completion subcommand added
133
- *
134
- * @example
135
- * ```typescript
136
- * const mainCommand = withCompletionCommand(
137
- * defineCommand({
138
- * name: "mycli",
139
- * subCommands: { ... },
140
- * }),
141
- * );
142
- * ```
143
- */
144
- function withCompletionCommand(command, options) {
145
- const { programName } = typeof options === "string" ? { programName: options } : options ?? {};
146
- const wrappedCommand = { ...command };
147
- wrappedCommand.subCommands = {
148
- ...command.subCommands,
149
- completion: createCompletionCommand(wrappedCommand, programName),
150
- __complete: require_zsh.createDynamicCompleteCommand(wrappedCommand, programName)
151
- };
152
- return wrappedCommand;
153
- }
154
-
155
- //#endregion
156
- exports.CompletionDirective = require_zsh.CompletionDirective;
157
- exports.createCompletionCommand = createCompletionCommand;
158
- exports.createDynamicCompleteCommand = require_zsh.createDynamicCompleteCommand;
159
- exports.detectShell = detectShell;
160
- exports.extractCompletionData = require_zsh.extractCompletionData;
161
- exports.extractPositionals = require_zsh.extractPositionals;
162
- exports.formatForShell = require_zsh.formatForShell;
163
- exports.generateCandidates = require_zsh.generateCandidates;
164
- exports.generateCompletion = generateCompletion;
165
- exports.getSupportedShells = getSupportedShells;
166
- exports.hasCompleteCommand = require_zsh.hasCompleteCommand;
167
- exports.parseCompletionContext = require_zsh.parseCompletionContext;
168
- exports.resolveValueCompletion = require_zsh.resolveValueCompletion;
169
- exports.withCompletionCommand = withCompletionCommand;
170
- //# sourceMappingURL=index.cjs.map
5
+ exports.CompletionDirective = require_completion.CompletionDirective;
6
+ exports.createCompletionCommand = require_completion.createCompletionCommand;
7
+ exports.createDynamicCompleteCommand = require_completion.createDynamicCompleteCommand;
8
+ exports.detectShell = require_completion.detectShell;
9
+ exports.extractCompletionData = require_completion.extractCompletionData;
10
+ exports.extractPositionals = require_completion.extractPositionals;
11
+ exports.formatForShell = require_completion.formatForShell;
12
+ exports.generateCandidates = require_completion.generateCandidates;
13
+ exports.generateCompletion = require_completion.generateCompletion;
14
+ exports.getSupportedShells = require_completion.getSupportedShells;
15
+ exports.hasCompleteCommand = require_completion.hasCompleteCommand;
16
+ exports.parseCompletionContext = require_completion.parseCompletionContext;
17
+ exports.resolveValueCompletion = require_completion.resolveValueCompletion;
18
+ exports.withCompletionCommand = require_completion.withCompletionCommand;
@@ -1,77 +1,2 @@
1
- import "../arg-registry-BNoIwnNr.cjs";
2
- import { d as Command, s as AnyCommand } from "../schema-extractor-DFaAZzaY.cjs";
3
- import { S as ShellType, _ as CompletableSubcommand, a as ShellFormatOptions, b as CompletionOptions, c as hasCompleteCommand, d as CompletionDirective, f as generateCandidates, g as CompletableOption, h as parseCompletionContext, i as extractPositionals, l as CandidateResult, m as CompletionType, n as resolveValueCompletion, o as formatForShell, p as CompletionContext, r as extractCompletionData, s as createDynamicCompleteCommand, t as ValueCompletionField, u as CompletionCandidate, v as CompletionData, x as CompletionResult, y as CompletionGenerator } from "../value-completion-resolver-BQgHsX7b.cjs";
4
- import { z } from "zod";
5
-
6
- //#region src/completion/index.d.ts
7
- /**
8
- * Generate completion script for the specified shell
9
- */
10
- declare function generateCompletion(command: AnyCommand, options: CompletionOptions): CompletionResult;
11
- /**
12
- * Get the list of supported shells
13
- */
14
- declare function getSupportedShells(): ShellType[];
15
- /**
16
- * Detect the current shell from environment
17
- */
18
- declare function detectShell(): ShellType | null;
19
- /**
20
- * Schema for the completion command arguments
21
- */
22
- declare const completionArgsSchema: z.ZodObject<{
23
- shell: z.ZodOptional<z.ZodEnum<{
24
- bash: "bash";
25
- zsh: "zsh";
26
- fish: "fish";
27
- }>>;
28
- instructions: z.ZodDefault<z.ZodBoolean>;
29
- }, z.core.$strip>;
30
- type CompletionArgs = z.infer<typeof completionArgsSchema>;
31
- /**
32
- * Create a completion subcommand for your CLI
33
- *
34
- * This creates a ready-to-use subcommand that generates completion scripts.
35
- *
36
- * @example
37
- * ```typescript
38
- * const mainCommand = defineCommand({
39
- * name: "mycli",
40
- * subCommands: {
41
- * completion: createCompletionCommand(mainCommand)
42
- * }
43
- * });
44
- * ```
45
- */
46
- declare function createCompletionCommand(rootCommand: AnyCommand, programName?: string): Command<typeof completionArgsSchema, CompletionArgs, any>;
47
- /**
48
- * Options for withCompletionCommand
49
- */
50
- interface WithCompletionOptions {
51
- /** Override the program name (defaults to command.name) */
52
- programName?: string;
53
- }
54
- /**
55
- * Wrap a command with a completion subcommand
56
- *
57
- * This avoids circular references that occur when a command references itself
58
- * in its subCommands (e.g., for completion generation).
59
- *
60
- * @param command - The command to wrap
61
- * @param options - Options including programName
62
- * @returns A new command with the completion subcommand added
63
- *
64
- * @example
65
- * ```typescript
66
- * const mainCommand = withCompletionCommand(
67
- * defineCommand({
68
- * name: "mycli",
69
- * subCommands: { ... },
70
- * }),
71
- * );
72
- * ```
73
- */
74
- declare function withCompletionCommand<T extends AnyCommand>(command: T, options?: string | WithCompletionOptions): T;
75
- //#endregion
76
- export { type CandidateResult, type CompletableOption, type CompletableSubcommand, type CompletionCandidate, type CompletionContext, type CompletionData, CompletionDirective, type CompletionGenerator, type CompletionOptions, type CompletionResult, type CompletionType, type ShellFormatOptions, type ShellType, type ValueCompletionField, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
77
- //# sourceMappingURL=index.d.cts.map
1
+ import { C as CompletableSubcommand, D as CompletionResult, E as CompletionOptions, O as ShellType, S as CompletableOption, T as CompletionGenerator, _ as CompletionDirective, a as getSupportedShells, b as CompletionType, c as resolveValueCompletion, d as ShellFormatOptions, f as formatForShell, g as CompletionCandidate, h as CandidateResult, i as generateCompletion, l as extractCompletionData, m as hasCompleteCommand, n as createCompletionCommand, o as withCompletionCommand, p as createDynamicCompleteCommand, r as detectShell, s as ValueCompletionField, t as WithCompletionOptions, u as extractPositionals, v as generateCandidates, w as CompletionData, x as parseCompletionContext, y as CompletionContext } from "../index-C5-0RXiH.cjs";
2
+ export { CandidateResult, CompletableOption, CompletableSubcommand, CompletionCandidate, CompletionContext, CompletionData, CompletionDirective, CompletionGenerator, CompletionOptions, CompletionResult, CompletionType, ShellFormatOptions, ShellType, ValueCompletionField, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
@@ -1,77 +1,2 @@
1
- import "../arg-registry-BUUhZ7JR.js";
2
- import { d as Command, s as AnyCommand } from "../schema-extractor-n9288WJ6.js";
3
- import { S as ShellType, _ as CompletableSubcommand, a as ShellFormatOptions, b as CompletionOptions, c as hasCompleteCommand, d as CompletionDirective, f as generateCandidates, g as CompletableOption, h as parseCompletionContext, i as extractPositionals, l as CandidateResult, m as CompletionType, n as resolveValueCompletion, o as formatForShell, p as CompletionContext, r as extractCompletionData, s as createDynamicCompleteCommand, t as ValueCompletionField, u as CompletionCandidate, v as CompletionData, x as CompletionResult, y as CompletionGenerator } from "../value-completion-resolver-C9LTGr0O.js";
4
- import { z } from "zod";
5
-
6
- //#region src/completion/index.d.ts
7
- /**
8
- * Generate completion script for the specified shell
9
- */
10
- declare function generateCompletion(command: AnyCommand, options: CompletionOptions): CompletionResult;
11
- /**
12
- * Get the list of supported shells
13
- */
14
- declare function getSupportedShells(): ShellType[];
15
- /**
16
- * Detect the current shell from environment
17
- */
18
- declare function detectShell(): ShellType | null;
19
- /**
20
- * Schema for the completion command arguments
21
- */
22
- declare const completionArgsSchema: z.ZodObject<{
23
- shell: z.ZodOptional<z.ZodEnum<{
24
- bash: "bash";
25
- zsh: "zsh";
26
- fish: "fish";
27
- }>>;
28
- instructions: z.ZodDefault<z.ZodBoolean>;
29
- }, z.core.$strip>;
30
- type CompletionArgs = z.infer<typeof completionArgsSchema>;
31
- /**
32
- * Create a completion subcommand for your CLI
33
- *
34
- * This creates a ready-to-use subcommand that generates completion scripts.
35
- *
36
- * @example
37
- * ```typescript
38
- * const mainCommand = defineCommand({
39
- * name: "mycli",
40
- * subCommands: {
41
- * completion: createCompletionCommand(mainCommand)
42
- * }
43
- * });
44
- * ```
45
- */
46
- declare function createCompletionCommand(rootCommand: AnyCommand, programName?: string): Command<typeof completionArgsSchema, CompletionArgs, any>;
47
- /**
48
- * Options for withCompletionCommand
49
- */
50
- interface WithCompletionOptions {
51
- /** Override the program name (defaults to command.name) */
52
- programName?: string;
53
- }
54
- /**
55
- * Wrap a command with a completion subcommand
56
- *
57
- * This avoids circular references that occur when a command references itself
58
- * in its subCommands (e.g., for completion generation).
59
- *
60
- * @param command - The command to wrap
61
- * @param options - Options including programName
62
- * @returns A new command with the completion subcommand added
63
- *
64
- * @example
65
- * ```typescript
66
- * const mainCommand = withCompletionCommand(
67
- * defineCommand({
68
- * name: "mycli",
69
- * subCommands: { ... },
70
- * }),
71
- * );
72
- * ```
73
- */
74
- declare function withCompletionCommand<T extends AnyCommand>(command: T, options?: string | WithCompletionOptions): T;
75
- //#endregion
76
- export { type CandidateResult, type CompletableOption, type CompletableSubcommand, type CompletionCandidate, type CompletionContext, type CompletionData, CompletionDirective, type CompletionGenerator, type CompletionOptions, type CompletionResult, type CompletionType, type ShellFormatOptions, type ShellType, type ValueCompletionField, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
77
- //# sourceMappingURL=index.d.ts.map
1
+ import { C as CompletableSubcommand, D as CompletionResult, E as CompletionOptions, O as ShellType, S as CompletableOption, T as CompletionGenerator, _ as CompletionDirective, a as getSupportedShells, b as CompletionType, c as resolveValueCompletion, d as ShellFormatOptions, f as formatForShell, g as CompletionCandidate, h as CandidateResult, i as generateCompletion, l as extractCompletionData, m as hasCompleteCommand, n as createCompletionCommand, o as withCompletionCommand, p as createDynamicCompleteCommand, r as detectShell, s as ValueCompletionField, t as WithCompletionOptions, u as extractPositionals, v as generateCandidates, w as CompletionData, x as parseCompletionContext, y as CompletionContext } from "../index-BZalbMeu.js";
2
+ export { CandidateResult, CompletableOption, CompletableSubcommand, CompletionCandidate, CompletionContext, CompletionData, CompletionDirective, CompletionGenerator, CompletionOptions, CompletionResult, CompletionType, ShellFormatOptions, ShellType, ValueCompletionField, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
@@ -1,155 +1,4 @@
1
- import { c as arg } from "../lazy-BrEg8SgI.js";
2
- import { a as formatForShell, c as generateCandidates, d as extractPositionals, f as resolveValueCompletion, i as hasCompleteCommand, l as generateBashCompletion, n as generateFishCompletion, o as parseCompletionContext, p as defineCommand, r as createDynamicCompleteCommand, s as CompletionDirective, t as generateZshCompletion, u as extractCompletionData } from "../zsh-hjvdI8uZ.js";
3
- import { z } from "zod";
1
+ import "../lazy-DSyfzR-F.js";
2
+ import { a as withCompletionCommand, c as formatForShell, d as generateCandidates, f as extractCompletionData, i as getSupportedShells, l as parseCompletionContext, m as resolveValueCompletion, n as detectShell, o as createDynamicCompleteCommand, p as extractPositionals, r as generateCompletion, s as hasCompleteCommand, t as createCompletionCommand, u as CompletionDirective } from "../completion-_AnQsWh9.js";
4
3
 
5
- //#region src/completion/index.ts
6
- /**
7
- * Shell completion generation module
8
- *
9
- * Provides utilities to generate shell completion scripts for bash, zsh, and fish.
10
- *
11
- * @example
12
- * ```typescript
13
- * import { generateCompletion, createCompletionCommand } from "politty/completion";
14
- *
15
- * // Generate completion script directly
16
- * const result = generateCompletion(myCommand, {
17
- * shell: "bash",
18
- * programName: "mycli"
19
- * });
20
- * console.log(result.script);
21
- *
22
- * // Or add a completion subcommand to your CLI
23
- * const mainCommand = withCompletionCommand(
24
- * defineCommand({
25
- * name: "mycli",
26
- * subCommands: { ... },
27
- * }),
28
- * );
29
- * ```
30
- */
31
- /**
32
- * Generate completion script for the specified shell
33
- */
34
- function generateCompletion(command, options) {
35
- switch (options.shell) {
36
- case "bash": return generateBashCompletion(command, options);
37
- case "zsh": return generateZshCompletion(command, options);
38
- case "fish": return generateFishCompletion(command, options);
39
- default: throw new Error(`Unsupported shell: ${options.shell}`);
40
- }
41
- }
42
- /**
43
- * Get the list of supported shells
44
- */
45
- function getSupportedShells() {
46
- return [
47
- "bash",
48
- "zsh",
49
- "fish"
50
- ];
51
- }
52
- /**
53
- * Detect the current shell from environment
54
- */
55
- function detectShell() {
56
- const shellName = (process.env.SHELL || "").split("/").pop()?.toLowerCase() || "";
57
- if (shellName.includes("bash")) return "bash";
58
- if (shellName.includes("zsh")) return "zsh";
59
- if (shellName.includes("fish")) return "fish";
60
- return null;
61
- }
62
- /**
63
- * Schema for the completion command arguments
64
- */
65
- const completionArgsSchema = z.object({
66
- shell: arg(z.enum([
67
- "bash",
68
- "zsh",
69
- "fish"
70
- ]).optional().describe("Shell type (auto-detected if not specified)"), {
71
- positional: true,
72
- description: "Shell type (bash, zsh, or fish)",
73
- placeholder: "SHELL"
74
- }),
75
- instructions: arg(z.boolean().default(false), {
76
- alias: "i",
77
- description: "Show installation instructions"
78
- })
79
- });
80
- /**
81
- * Create a completion subcommand for your CLI
82
- *
83
- * This creates a ready-to-use subcommand that generates completion scripts.
84
- *
85
- * @example
86
- * ```typescript
87
- * const mainCommand = defineCommand({
88
- * name: "mycli",
89
- * subCommands: {
90
- * completion: createCompletionCommand(mainCommand)
91
- * }
92
- * });
93
- * ```
94
- */
95
- function createCompletionCommand(rootCommand, programName) {
96
- const resolvedProgramName = programName ?? rootCommand.name;
97
- if (!rootCommand.subCommands?.__complete) rootCommand.subCommands = {
98
- ...rootCommand.subCommands,
99
- __complete: createDynamicCompleteCommand(rootCommand, resolvedProgramName)
100
- };
101
- return defineCommand({
102
- name: "completion",
103
- description: "Generate shell completion script",
104
- args: completionArgsSchema,
105
- run(args) {
106
- const shellType = args.shell || detectShell();
107
- if (!shellType) {
108
- console.error("Could not detect shell type. Please specify one of: bash, zsh, fish");
109
- process.exitCode = 1;
110
- return;
111
- }
112
- const result = generateCompletion(rootCommand, {
113
- shell: shellType,
114
- programName: resolvedProgramName,
115
- includeDescriptions: true
116
- });
117
- if (args.instructions) console.log(result.installInstructions);
118
- else console.log(result.script);
119
- }
120
- });
121
- }
122
- /**
123
- * Wrap a command with a completion subcommand
124
- *
125
- * This avoids circular references that occur when a command references itself
126
- * in its subCommands (e.g., for completion generation).
127
- *
128
- * @param command - The command to wrap
129
- * @param options - Options including programName
130
- * @returns A new command with the completion subcommand added
131
- *
132
- * @example
133
- * ```typescript
134
- * const mainCommand = withCompletionCommand(
135
- * defineCommand({
136
- * name: "mycli",
137
- * subCommands: { ... },
138
- * }),
139
- * );
140
- * ```
141
- */
142
- function withCompletionCommand(command, options) {
143
- const { programName } = typeof options === "string" ? { programName: options } : options ?? {};
144
- const wrappedCommand = { ...command };
145
- wrappedCommand.subCommands = {
146
- ...command.subCommands,
147
- completion: createCompletionCommand(wrappedCommand, programName),
148
- __complete: createDynamicCompleteCommand(wrappedCommand, programName)
149
- };
150
- return wrappedCommand;
151
- }
152
-
153
- //#endregion
154
- export { CompletionDirective, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
155
- //# sourceMappingURL=index.js.map
4
+ export { CompletionDirective, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };