politty 0.4.1 → 0.4.3
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/{arg-registry-C3GP-5C9.d.ts → arg-registry-BNoIwnNr.d.cts} +15 -8
- package/dist/arg-registry-BNoIwnNr.d.cts.map +1 -0
- package/dist/{arg-registry-B4a4Fj7f.d.cts → arg-registry-BUUhZ7JR.d.ts} +15 -8
- package/dist/arg-registry-BUUhZ7JR.d.ts.map +1 -0
- package/dist/augment.d.cts +1 -1
- package/dist/augment.d.ts +1 -1
- package/dist/completion/index.cjs +20 -20
- package/dist/completion/index.cjs.map +1 -1
- package/dist/completion/index.d.cts +3 -3
- package/dist/completion/index.d.ts +3 -3
- package/dist/completion/index.js +2 -2
- package/dist/docs/index.cjs +6 -6
- package/dist/docs/index.cjs.map +1 -1
- package/dist/docs/index.d.cts +3 -3
- package/dist/docs/index.d.cts.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +3 -3
- package/dist/index.cjs +10 -8
- package/dist/index.d.cts +4 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/{schema-extractor-Mk1MHBkQ.cjs → lazy-BEDnSR0m.cjs} +77 -2
- package/dist/lazy-BEDnSR0m.cjs.map +1 -0
- package/dist/{schema-extractor-DAkmmrOy.js → lazy-BrEg8SgI.js} +59 -2
- package/dist/lazy-BrEg8SgI.js.map +1 -0
- package/dist/{runner-0yr2HFay.cjs → runner-C4fSHJMe.cjs} +11 -10
- package/dist/runner-C4fSHJMe.cjs.map +1 -0
- package/dist/{runner-BoZpJtIR.js → runner-D6k4BgB4.js} +6 -5
- package/dist/runner-D6k4BgB4.js.map +1 -0
- package/dist/{schema-extractor-DyfK21m_.d.cts → schema-extractor-DFaAZzaY.d.cts} +49 -4
- package/dist/schema-extractor-DFaAZzaY.d.cts.map +1 -0
- package/dist/{schema-extractor-CHiBRT39.d.ts → schema-extractor-n9288WJ6.d.ts} +49 -4
- package/dist/schema-extractor-n9288WJ6.d.ts.map +1 -0
- package/dist/{subcommand-router-DtCeT_O9.js → subcommand-router-CAzBsLSI.js} +4 -1
- package/dist/{subcommand-router-DtCeT_O9.js.map → subcommand-router-CAzBsLSI.js.map} +1 -1
- package/dist/{subcommand-router-4d1Xbp8B.cjs → subcommand-router-ZjNjFaUL.cjs} +3 -1
- package/dist/subcommand-router-ZjNjFaUL.cjs.map +1 -0
- package/dist/{value-completion-resolver-0xf8_07p.d.cts → value-completion-resolver-BQgHsX7b.d.cts} +20 -12
- package/dist/value-completion-resolver-BQgHsX7b.d.cts.map +1 -0
- package/dist/{value-completion-resolver-CUKbibx-.d.ts → value-completion-resolver-C9LTGr0O.d.ts} +20 -12
- package/dist/value-completion-resolver-C9LTGr0O.d.ts.map +1 -0
- package/dist/zsh-CASZWn0o.cjs +1586 -0
- package/dist/zsh-CASZWn0o.cjs.map +1 -0
- package/dist/zsh-hjvdI8uZ.js +1508 -0
- package/dist/zsh-hjvdI8uZ.js.map +1 -0
- package/package.json +4 -4
- package/dist/arg-registry-B4a4Fj7f.d.cts.map +0 -1
- package/dist/arg-registry-C3GP-5C9.d.ts.map +0 -1
- package/dist/extractor-DO-FDKkW.js +0 -1000
- package/dist/extractor-DO-FDKkW.js.map +0 -1
- package/dist/extractor-cjruDqQ2.cjs +0 -1078
- package/dist/extractor-cjruDqQ2.cjs.map +0 -1
- package/dist/runner-0yr2HFay.cjs.map +0 -1
- package/dist/runner-BoZpJtIR.js.map +0 -1
- package/dist/schema-extractor-CHiBRT39.d.ts.map +0 -1
- package/dist/schema-extractor-DAkmmrOy.js.map +0 -1
- package/dist/schema-extractor-DyfK21m_.d.cts.map +0 -1
- package/dist/schema-extractor-Mk1MHBkQ.cjs.map +0 -1
- package/dist/subcommand-router-4d1Xbp8B.cjs.map +0 -1
- package/dist/value-completion-resolver-0xf8_07p.d.cts.map +0 -1
- package/dist/value-completion-resolver-CUKbibx-.d.ts.map +0 -1
|
@@ -38,16 +38,23 @@ interface CustomCompletion {
|
|
|
38
38
|
* branch: arg(z.string(), {
|
|
39
39
|
* completion: { custom: { shellCommand: "git branch --format='%(refname:short)'" } }
|
|
40
40
|
* })
|
|
41
|
+
*
|
|
42
|
+
* // File completion with glob pattern matcher
|
|
43
|
+
* envFile: arg(z.string(), {
|
|
44
|
+
* completion: { type: "file", matcher: [".env.*"] }
|
|
45
|
+
* })
|
|
41
46
|
* ```
|
|
42
47
|
*/
|
|
43
|
-
|
|
44
|
-
/** Built-in completion type */
|
|
45
|
-
type?: CompletionType;
|
|
46
|
-
/** Custom completion (takes precedence over type if both specified) */
|
|
48
|
+
type CompletionMeta = {
|
|
49
|
+
/** Built-in completion type */type?: CompletionType; /** Custom completion (takes precedence over type if both specified) */
|
|
47
50
|
custom?: CustomCompletion;
|
|
48
|
-
|
|
49
|
-
extensions?: string[];
|
|
50
|
-
|
|
51
|
+
} & ({
|
|
52
|
+
/** File extension filter (only applies when type is "file") */extensions?: string[];
|
|
53
|
+
matcher?: never;
|
|
54
|
+
} | {
|
|
55
|
+
/** Glob patterns for file matching (only applies when type is "file") */matcher?: string[];
|
|
56
|
+
extensions?: never;
|
|
57
|
+
});
|
|
51
58
|
/**
|
|
52
59
|
* Base metadata shared by all argument types
|
|
53
60
|
*/
|
|
@@ -134,4 +141,4 @@ declare function arg<T extends z.ZodType>(schema: T): T;
|
|
|
134
141
|
declare function arg<T extends z.ZodType, M extends ArgMeta>(schema: T, meta: ValidateArgMeta<M>): T;
|
|
135
142
|
//#endregion
|
|
136
143
|
export { arg as a, CustomCompletion as i, CompletionMeta as n, CompletionType as r, ArgMeta as t };
|
|
137
|
-
//# sourceMappingURL=arg-registry-
|
|
144
|
+
//# sourceMappingURL=arg-registry-BNoIwnNr.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arg-registry-BNoIwnNr.d.cts","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"}
|
|
@@ -38,16 +38,23 @@ interface CustomCompletion {
|
|
|
38
38
|
* branch: arg(z.string(), {
|
|
39
39
|
* completion: { custom: { shellCommand: "git branch --format='%(refname:short)'" } }
|
|
40
40
|
* })
|
|
41
|
+
*
|
|
42
|
+
* // File completion with glob pattern matcher
|
|
43
|
+
* envFile: arg(z.string(), {
|
|
44
|
+
* completion: { type: "file", matcher: [".env.*"] }
|
|
45
|
+
* })
|
|
41
46
|
* ```
|
|
42
47
|
*/
|
|
43
|
-
|
|
44
|
-
/** Built-in completion type */
|
|
45
|
-
type?: CompletionType;
|
|
46
|
-
/** Custom completion (takes precedence over type if both specified) */
|
|
48
|
+
type CompletionMeta = {
|
|
49
|
+
/** Built-in completion type */type?: CompletionType; /** Custom completion (takes precedence over type if both specified) */
|
|
47
50
|
custom?: CustomCompletion;
|
|
48
|
-
|
|
49
|
-
extensions?: string[];
|
|
50
|
-
|
|
51
|
+
} & ({
|
|
52
|
+
/** File extension filter (only applies when type is "file") */extensions?: string[];
|
|
53
|
+
matcher?: never;
|
|
54
|
+
} | {
|
|
55
|
+
/** Glob patterns for file matching (only applies when type is "file") */matcher?: string[];
|
|
56
|
+
extensions?: never;
|
|
57
|
+
});
|
|
51
58
|
/**
|
|
52
59
|
* Base metadata shared by all argument types
|
|
53
60
|
*/
|
|
@@ -134,4 +141,4 @@ declare function arg<T extends z.ZodType>(schema: T): T;
|
|
|
134
141
|
declare function arg<T extends z.ZodType, M extends ArgMeta>(schema: T, meta: ValidateArgMeta<M>): T;
|
|
135
142
|
//#endregion
|
|
136
143
|
export { arg as a, CustomCompletion as i, CompletionMeta as n, CompletionType as r, ArgMeta as t };
|
|
137
|
-
//# sourceMappingURL=arg-registry-
|
|
144
|
+
//# sourceMappingURL=arg-registry-BUUhZ7JR.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/augment.d.cts
CHANGED
package/dist/augment.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_subcommand_router = require('../subcommand-router-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
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
5
|
let zod = require("zod");
|
|
6
6
|
|
|
7
7
|
//#region src/completion/index.ts
|
|
@@ -35,9 +35,9 @@ let zod = require("zod");
|
|
|
35
35
|
*/
|
|
36
36
|
function generateCompletion(command, options) {
|
|
37
37
|
switch (options.shell) {
|
|
38
|
-
case "bash": return
|
|
39
|
-
case "zsh": return
|
|
40
|
-
case "fish": return
|
|
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
41
|
default: throw new Error(`Unsupported shell: ${options.shell}`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -65,7 +65,7 @@ function detectShell() {
|
|
|
65
65
|
* Schema for the completion command arguments
|
|
66
66
|
*/
|
|
67
67
|
const completionArgsSchema = zod.z.object({
|
|
68
|
-
shell:
|
|
68
|
+
shell: require_lazy.arg(zod.z.enum([
|
|
69
69
|
"bash",
|
|
70
70
|
"zsh",
|
|
71
71
|
"fish"
|
|
@@ -74,7 +74,7 @@ const completionArgsSchema = zod.z.object({
|
|
|
74
74
|
description: "Shell type (bash, zsh, or fish)",
|
|
75
75
|
placeholder: "SHELL"
|
|
76
76
|
}),
|
|
77
|
-
instructions:
|
|
77
|
+
instructions: require_lazy.arg(zod.z.boolean().default(false), {
|
|
78
78
|
alias: "i",
|
|
79
79
|
description: "Show installation instructions"
|
|
80
80
|
})
|
|
@@ -98,9 +98,9 @@ function createCompletionCommand(rootCommand, programName) {
|
|
|
98
98
|
const resolvedProgramName = programName ?? rootCommand.name;
|
|
99
99
|
if (!rootCommand.subCommands?.__complete) rootCommand.subCommands = {
|
|
100
100
|
...rootCommand.subCommands,
|
|
101
|
-
__complete:
|
|
101
|
+
__complete: require_zsh.createDynamicCompleteCommand(rootCommand, resolvedProgramName)
|
|
102
102
|
};
|
|
103
|
-
return
|
|
103
|
+
return require_zsh.defineCommand({
|
|
104
104
|
name: "completion",
|
|
105
105
|
description: "Generate shell completion script",
|
|
106
106
|
args: completionArgsSchema,
|
|
@@ -147,24 +147,24 @@ function withCompletionCommand(command, options) {
|
|
|
147
147
|
wrappedCommand.subCommands = {
|
|
148
148
|
...command.subCommands,
|
|
149
149
|
completion: createCompletionCommand(wrappedCommand, programName),
|
|
150
|
-
__complete:
|
|
150
|
+
__complete: require_zsh.createDynamicCompleteCommand(wrappedCommand, programName)
|
|
151
151
|
};
|
|
152
152
|
return wrappedCommand;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
//#endregion
|
|
156
|
-
exports.CompletionDirective =
|
|
156
|
+
exports.CompletionDirective = require_zsh.CompletionDirective;
|
|
157
157
|
exports.createCompletionCommand = createCompletionCommand;
|
|
158
|
-
exports.createDynamicCompleteCommand =
|
|
158
|
+
exports.createDynamicCompleteCommand = require_zsh.createDynamicCompleteCommand;
|
|
159
159
|
exports.detectShell = detectShell;
|
|
160
|
-
exports.extractCompletionData =
|
|
161
|
-
exports.extractPositionals =
|
|
162
|
-
exports.formatForShell =
|
|
163
|
-
exports.generateCandidates =
|
|
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
164
|
exports.generateCompletion = generateCompletion;
|
|
165
165
|
exports.getSupportedShells = getSupportedShells;
|
|
166
|
-
exports.hasCompleteCommand =
|
|
167
|
-
exports.parseCompletionContext =
|
|
168
|
-
exports.resolveValueCompletion =
|
|
166
|
+
exports.hasCompleteCommand = require_zsh.hasCompleteCommand;
|
|
167
|
+
exports.parseCompletionContext = require_zsh.parseCompletionContext;
|
|
168
|
+
exports.resolveValueCompletion = require_zsh.resolveValueCompletion;
|
|
169
169
|
exports.withCompletionCommand = withCompletionCommand;
|
|
170
170
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["generateBashCompletion","generateZshCompletion","generateFishCompletion","z","arg","createDynamicCompleteCommand","defineCommand"],"sources":["../../src/completion/index.ts"],"sourcesContent":["/**\n * Shell completion generation module\n *\n * Provides utilities to generate shell completion scripts for bash, zsh, and fish.\n *\n * @example\n * ```typescript\n * import { generateCompletion, createCompletionCommand } from \"politty/completion\";\n *\n * // Generate completion script directly\n * const result = generateCompletion(myCommand, {\n * shell: \"bash\",\n * programName: \"mycli\"\n * });\n * console.log(result.script);\n *\n * // Or add a completion subcommand to your CLI\n * const mainCommand = withCompletionCommand(\n * defineCommand({\n * name: \"mycli\",\n * subCommands: { ... },\n * }),\n * );\n * ```\n */\n\nimport { z } from \"zod\";\nimport { arg } from \"../core/arg-registry.js\";\nimport { defineCommand } from \"../core/command.js\";\nimport type { AnyCommand, Command } from \"../types.js\";\nimport { generateBashCompletion } from \"./bash.js\";\nimport { createDynamicCompleteCommand } from \"./dynamic/index.js\";\nimport { generateFishCompletion } from \"./fish.js\";\nimport type { CompletionOptions, CompletionResult, ShellType } from \"./types.js\";\nimport { generateZshCompletion } from \"./zsh.js\";\n\n// Re-export dynamic completion\nexport {\n CompletionDirective,\n createDynamicCompleteCommand,\n formatForShell,\n generateCandidates,\n hasCompleteCommand,\n parseCompletionContext,\n type CandidateResult,\n type CompletionCandidate,\n type CompletionContext,\n type CompletionType,\n type ShellFormatOptions,\n} from \"./dynamic/index.js\";\n// Re-export extractor\nexport { extractCompletionData, extractPositionals } from \"./extractor.js\";\n// Re-export types\nexport type {\n CompletableOption,\n CompletableSubcommand,\n CompletionData,\n CompletionGenerator,\n CompletionOptions,\n CompletionResult,\n ShellType,\n} from \"./types.js\";\n// Re-export value completion resolver\nexport { resolveValueCompletion, type ValueCompletionField } from \"./value-completion-resolver.js\";\n\n/**\n * Generate completion script for the specified shell\n */\nexport function generateCompletion(\n command: AnyCommand,\n options: CompletionOptions,\n): CompletionResult {\n switch (options.shell) {\n case \"bash\":\n return generateBashCompletion(command, options);\n case \"zsh\":\n return generateZshCompletion(command, options);\n case \"fish\":\n return generateFishCompletion(command, options);\n default:\n throw new Error(`Unsupported shell: ${options.shell}`);\n }\n}\n\n/**\n * Get the list of supported shells\n */\nexport function getSupportedShells(): ShellType[] {\n return [\"bash\", \"zsh\", \"fish\"];\n}\n\n/**\n * Detect the current shell from environment\n */\nexport function detectShell(): ShellType | null {\n const shell = process.env.SHELL || \"\";\n const shellName = shell.split(\"/\").pop()?.toLowerCase() || \"\";\n\n if (shellName.includes(\"bash\")) {\n return \"bash\";\n }\n if (shellName.includes(\"zsh\")) {\n return \"zsh\";\n }\n if (shellName.includes(\"fish\")) {\n return \"fish\";\n }\n\n return null;\n}\n\n/**\n * Schema for the completion command arguments\n */\nconst completionArgsSchema = z.object({\n shell: arg(\n z\n .enum([\"bash\", \"zsh\", \"fish\"])\n .optional()\n .describe(\"Shell type (auto-detected if not specified)\"),\n {\n positional: true,\n description: \"Shell type (bash, zsh, or fish)\",\n placeholder: \"SHELL\",\n },\n ),\n instructions: arg(z.boolean().default(false), {\n alias: \"i\",\n description: \"Show installation instructions\",\n }),\n});\n\ntype CompletionArgs = z.infer<typeof completionArgsSchema>;\n\n/**\n * Create a completion subcommand for your CLI\n *\n * This creates a ready-to-use subcommand that generates completion scripts.\n *\n * @example\n * ```typescript\n * const mainCommand = defineCommand({\n * name: \"mycli\",\n * subCommands: {\n * completion: createCompletionCommand(mainCommand)\n * }\n * });\n * ```\n */\nexport function createCompletionCommand(\n rootCommand: AnyCommand,\n programName?: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Command<typeof completionArgsSchema, CompletionArgs, any> {\n const resolvedProgramName = programName ?? rootCommand.name;\n\n if (!rootCommand.subCommands?.__complete) {\n rootCommand.subCommands = {\n ...rootCommand.subCommands,\n __complete: createDynamicCompleteCommand(rootCommand, resolvedProgramName),\n };\n }\n\n return defineCommand({\n name: \"completion\",\n description: \"Generate shell completion script\",\n args: completionArgsSchema,\n run(args) {\n // Detect shell if not specified\n const shellType = args.shell || detectShell();\n\n if (!shellType) {\n console.error(\"Could not detect shell type. Please specify one of: bash, zsh, fish\");\n process.exitCode = 1;\n return;\n }\n\n const result = generateCompletion(rootCommand, {\n shell: shellType,\n programName: resolvedProgramName,\n includeDescriptions: true,\n });\n\n if (args.instructions) {\n console.log(result.installInstructions);\n } else {\n console.log(result.script);\n }\n },\n });\n}\n\n/**\n * Options for withCompletionCommand\n */\nexport interface WithCompletionOptions {\n /** Override the program name (defaults to command.name) */\n programName?: string;\n}\n\n/**\n * Wrap a command with a completion subcommand\n *\n * This avoids circular references that occur when a command references itself\n * in its subCommands (e.g., for completion generation).\n *\n * @param command - The command to wrap\n * @param options - Options including programName\n * @returns A new command with the completion subcommand added\n *\n * @example\n * ```typescript\n * const mainCommand = withCompletionCommand(\n * defineCommand({\n * name: \"mycli\",\n * subCommands: { ... },\n * }),\n * );\n * ```\n */\nexport function withCompletionCommand<T extends AnyCommand>(\n command: T,\n options?: string | WithCompletionOptions,\n): T {\n // Support both string (programName) and options object for backwards compatibility\n const opts: WithCompletionOptions =\n typeof options === \"string\" ? { programName: options } : (options ?? {});\n\n const { programName } = opts;\n\n const wrappedCommand = {\n ...command,\n } as T;\n\n wrappedCommand.subCommands = {\n ...command.subCommands,\n completion: createCompletionCommand(wrappedCommand, programName),\n __complete: createDynamicCompleteCommand(wrappedCommand, programName),\n };\n\n return wrappedCommand;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,mBACd,SACA,SACkB;AAClB,SAAQ,QAAQ,OAAhB;EACE,KAAK,OACH,QAAOA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["generateBashCompletion","generateZshCompletion","generateFishCompletion","z","arg","createDynamicCompleteCommand","defineCommand"],"sources":["../../src/completion/index.ts"],"sourcesContent":["/**\n * Shell completion generation module\n *\n * Provides utilities to generate shell completion scripts for bash, zsh, and fish.\n *\n * @example\n * ```typescript\n * import { generateCompletion, createCompletionCommand } from \"politty/completion\";\n *\n * // Generate completion script directly\n * const result = generateCompletion(myCommand, {\n * shell: \"bash\",\n * programName: \"mycli\"\n * });\n * console.log(result.script);\n *\n * // Or add a completion subcommand to your CLI\n * const mainCommand = withCompletionCommand(\n * defineCommand({\n * name: \"mycli\",\n * subCommands: { ... },\n * }),\n * );\n * ```\n */\n\nimport { z } from \"zod\";\nimport { arg } from \"../core/arg-registry.js\";\nimport { defineCommand } from \"../core/command.js\";\nimport type { AnyCommand, Command } from \"../types.js\";\nimport { generateBashCompletion } from \"./bash.js\";\nimport { createDynamicCompleteCommand } from \"./dynamic/index.js\";\nimport { generateFishCompletion } from \"./fish.js\";\nimport type { CompletionOptions, CompletionResult, ShellType } from \"./types.js\";\nimport { generateZshCompletion } from \"./zsh.js\";\n\n// Re-export dynamic completion\nexport {\n CompletionDirective,\n createDynamicCompleteCommand,\n formatForShell,\n generateCandidates,\n hasCompleteCommand,\n parseCompletionContext,\n type CandidateResult,\n type CompletionCandidate,\n type CompletionContext,\n type CompletionType,\n type ShellFormatOptions,\n} from \"./dynamic/index.js\";\n// Re-export extractor\nexport { extractCompletionData, extractPositionals } from \"./extractor.js\";\n// Re-export types\nexport type {\n CompletableOption,\n CompletableSubcommand,\n CompletionData,\n CompletionGenerator,\n CompletionOptions,\n CompletionResult,\n ShellType,\n} from \"./types.js\";\n// Re-export value completion resolver\nexport { resolveValueCompletion, type ValueCompletionField } from \"./value-completion-resolver.js\";\n\n/**\n * Generate completion script for the specified shell\n */\nexport function generateCompletion(\n command: AnyCommand,\n options: CompletionOptions,\n): CompletionResult {\n switch (options.shell) {\n case \"bash\":\n return generateBashCompletion(command, options);\n case \"zsh\":\n return generateZshCompletion(command, options);\n case \"fish\":\n return generateFishCompletion(command, options);\n default:\n throw new Error(`Unsupported shell: ${options.shell}`);\n }\n}\n\n/**\n * Get the list of supported shells\n */\nexport function getSupportedShells(): ShellType[] {\n return [\"bash\", \"zsh\", \"fish\"];\n}\n\n/**\n * Detect the current shell from environment\n */\nexport function detectShell(): ShellType | null {\n const shell = process.env.SHELL || \"\";\n const shellName = shell.split(\"/\").pop()?.toLowerCase() || \"\";\n\n if (shellName.includes(\"bash\")) {\n return \"bash\";\n }\n if (shellName.includes(\"zsh\")) {\n return \"zsh\";\n }\n if (shellName.includes(\"fish\")) {\n return \"fish\";\n }\n\n return null;\n}\n\n/**\n * Schema for the completion command arguments\n */\nconst completionArgsSchema = z.object({\n shell: arg(\n z\n .enum([\"bash\", \"zsh\", \"fish\"])\n .optional()\n .describe(\"Shell type (auto-detected if not specified)\"),\n {\n positional: true,\n description: \"Shell type (bash, zsh, or fish)\",\n placeholder: \"SHELL\",\n },\n ),\n instructions: arg(z.boolean().default(false), {\n alias: \"i\",\n description: \"Show installation instructions\",\n }),\n});\n\ntype CompletionArgs = z.infer<typeof completionArgsSchema>;\n\n/**\n * Create a completion subcommand for your CLI\n *\n * This creates a ready-to-use subcommand that generates completion scripts.\n *\n * @example\n * ```typescript\n * const mainCommand = defineCommand({\n * name: \"mycli\",\n * subCommands: {\n * completion: createCompletionCommand(mainCommand)\n * }\n * });\n * ```\n */\nexport function createCompletionCommand(\n rootCommand: AnyCommand,\n programName?: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Command<typeof completionArgsSchema, CompletionArgs, any> {\n const resolvedProgramName = programName ?? rootCommand.name;\n\n if (!rootCommand.subCommands?.__complete) {\n rootCommand.subCommands = {\n ...rootCommand.subCommands,\n __complete: createDynamicCompleteCommand(rootCommand, resolvedProgramName),\n };\n }\n\n return defineCommand({\n name: \"completion\",\n description: \"Generate shell completion script\",\n args: completionArgsSchema,\n run(args) {\n // Detect shell if not specified\n const shellType = args.shell || detectShell();\n\n if (!shellType) {\n console.error(\"Could not detect shell type. Please specify one of: bash, zsh, fish\");\n process.exitCode = 1;\n return;\n }\n\n const result = generateCompletion(rootCommand, {\n shell: shellType,\n programName: resolvedProgramName,\n includeDescriptions: true,\n });\n\n if (args.instructions) {\n console.log(result.installInstructions);\n } else {\n console.log(result.script);\n }\n },\n });\n}\n\n/**\n * Options for withCompletionCommand\n */\nexport interface WithCompletionOptions {\n /** Override the program name (defaults to command.name) */\n programName?: string;\n}\n\n/**\n * Wrap a command with a completion subcommand\n *\n * This avoids circular references that occur when a command references itself\n * in its subCommands (e.g., for completion generation).\n *\n * @param command - The command to wrap\n * @param options - Options including programName\n * @returns A new command with the completion subcommand added\n *\n * @example\n * ```typescript\n * const mainCommand = withCompletionCommand(\n * defineCommand({\n * name: \"mycli\",\n * subCommands: { ... },\n * }),\n * );\n * ```\n */\nexport function withCompletionCommand<T extends AnyCommand>(\n command: T,\n options?: string | WithCompletionOptions,\n): T {\n // Support both string (programName) and options object for backwards compatibility\n const opts: WithCompletionOptions =\n typeof options === \"string\" ? { programName: options } : (options ?? {});\n\n const { programName } = opts;\n\n const wrappedCommand = {\n ...command,\n } as T;\n\n wrappedCommand.subCommands = {\n ...command.subCommands,\n completion: createCompletionCommand(wrappedCommand, programName),\n __complete: createDynamicCompleteCommand(wrappedCommand, programName),\n };\n\n return wrappedCommand;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,mBACd,SACA,SACkB;AAClB,SAAQ,QAAQ,OAAhB;EACE,KAAK,OACH,QAAOA,mCAAuB,SAAS,QAAQ;EACjD,KAAK,MACH,QAAOC,kCAAsB,SAAS,QAAQ;EAChD,KAAK,OACH,QAAOC,mCAAuB,SAAS,QAAQ;EACjD,QACE,OAAM,IAAI,MAAM,sBAAsB,QAAQ,QAAQ;;;;;;AAO5D,SAAgB,qBAAkC;AAChD,QAAO;EAAC;EAAQ;EAAO;EAAO;;;;;AAMhC,SAAgB,cAAgC;CAE9C,MAAM,aADQ,QAAQ,IAAI,SAAS,IACX,MAAM,IAAI,CAAC,KAAK,EAAE,aAAa,IAAI;AAE3D,KAAI,UAAU,SAAS,OAAO,CAC5B,QAAO;AAET,KAAI,UAAU,SAAS,MAAM,CAC3B,QAAO;AAET,KAAI,UAAU,SAAS,OAAO,CAC5B,QAAO;AAGT,QAAO;;;;;AAMT,MAAM,uBAAuBC,MAAE,OAAO;CACpC,OAAOC,iBACLD,MACG,KAAK;EAAC;EAAQ;EAAO;EAAO,CAAC,CAC7B,UAAU,CACV,SAAS,8CAA8C,EAC1D;EACE,YAAY;EACZ,aAAa;EACb,aAAa;EACd,CACF;CACD,cAAcC,iBAAID,MAAE,SAAS,CAAC,QAAQ,MAAM,EAAE;EAC5C,OAAO;EACP,aAAa;EACd,CAAC;CACH,CAAC;;;;;;;;;;;;;;;;AAmBF,SAAgB,wBACd,aACA,aAE2D;CAC3D,MAAM,sBAAsB,eAAe,YAAY;AAEvD,KAAI,CAAC,YAAY,aAAa,WAC5B,aAAY,cAAc;EACxB,GAAG,YAAY;EACf,YAAYE,yCAA6B,aAAa,oBAAoB;EAC3E;AAGH,QAAOC,0BAAc;EACnB,MAAM;EACN,aAAa;EACb,MAAM;EACN,IAAI,MAAM;GAER,MAAM,YAAY,KAAK,SAAS,aAAa;AAE7C,OAAI,CAAC,WAAW;AACd,YAAQ,MAAM,sEAAsE;AACpF,YAAQ,WAAW;AACnB;;GAGF,MAAM,SAAS,mBAAmB,aAAa;IAC7C,OAAO;IACP,aAAa;IACb,qBAAqB;IACtB,CAAC;AAEF,OAAI,KAAK,aACP,SAAQ,IAAI,OAAO,oBAAoB;OAEvC,SAAQ,IAAI,OAAO,OAAO;;EAG/B,CAAC;;;;;;;;;;;;;;;;;;;;;;AA+BJ,SAAgB,sBACd,SACA,SACG;CAKH,MAAM,EAAE,gBAFN,OAAO,YAAY,WAAW,EAAE,aAAa,SAAS,GAAI,WAAW,EAAE;CAIzE,MAAM,iBAAiB,EACrB,GAAG,SACJ;AAED,gBAAe,cAAc;EAC3B,GAAG,QAAQ;EACX,YAAY,wBAAwB,gBAAgB,YAAY;EAChE,YAAYD,yCAA6B,gBAAgB,YAAY;EACtE;AAED,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../arg-registry-
|
|
2
|
-
import { d as Command, s as AnyCommand } from "../schema-extractor-
|
|
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-
|
|
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
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/completion/index.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../arg-registry-
|
|
2
|
-
import { d as Command, s as AnyCommand } from "../schema-extractor-
|
|
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-
|
|
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
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/completion/index.d.ts
|
package/dist/completion/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
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
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
5
|
//#region src/completion/index.ts
|
package/dist/docs/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_subcommand_router = require('../subcommand-router-
|
|
3
|
-
const
|
|
2
|
+
const require_subcommand_router = require('../subcommand-router-ZjNjFaUL.cjs');
|
|
3
|
+
const require_lazy = require('../lazy-BEDnSR0m.cjs');
|
|
4
4
|
let zod = require("zod");
|
|
5
5
|
let node_util = require("node:util");
|
|
6
6
|
let node_fs = require("node:fs");
|
|
@@ -644,7 +644,7 @@ function deleteFile(filePath, fileSystem = node_fs) {
|
|
|
644
644
|
* Build CommandInfo from a command
|
|
645
645
|
*/
|
|
646
646
|
async function buildCommandInfo(command, rootName, commandPath = []) {
|
|
647
|
-
const extracted =
|
|
647
|
+
const extracted = require_lazy.getExtractedFields(command);
|
|
648
648
|
const positionalArgs = extracted?.fields.filter((f) => f.positional) ?? [];
|
|
649
649
|
const options = extracted?.fields.filter((f) => !f.positional) ?? [];
|
|
650
650
|
const subCommands = [];
|
|
@@ -723,7 +723,7 @@ async function executeSingleExample(example, rootCommand, commandPath) {
|
|
|
723
723
|
collector.start();
|
|
724
724
|
let success = true;
|
|
725
725
|
try {
|
|
726
|
-
const { runCommand } = await Promise.resolve().then(() => require("../runner-
|
|
726
|
+
const { runCommand } = await Promise.resolve().then(() => require("../runner-C4fSHJMe.cjs")).then((n) => n.runner_exports);
|
|
727
727
|
const result = await runCommand(rootCommand, argv);
|
|
728
728
|
success = result.success;
|
|
729
729
|
if (!result.success && result.error) console.error(result.error.message);
|
|
@@ -787,7 +787,7 @@ function parseExampleCmd(cmd) {
|
|
|
787
787
|
* ResolvedFieldMeta format used by politty's rendering functions.
|
|
788
788
|
*/
|
|
789
789
|
function extractArgsFields(args) {
|
|
790
|
-
return
|
|
790
|
+
return require_lazy.extractFields(zod.z.object(args)).fields;
|
|
791
791
|
}
|
|
792
792
|
/**
|
|
793
793
|
* Render args definition as a markdown options table
|
|
@@ -1350,7 +1350,7 @@ function isGlobalOptionsConfigWithOptions(config) {
|
|
|
1350
1350
|
* Positional args are not rendered in args tables, so they must not be excluded.
|
|
1351
1351
|
*/
|
|
1352
1352
|
function collectRenderableGlobalOptionFields(argsShape) {
|
|
1353
|
-
return
|
|
1353
|
+
return require_lazy.extractFields(zod.z.object(argsShape)).fields.filter((field) => !field.positional);
|
|
1354
1354
|
}
|
|
1355
1355
|
/**
|
|
1356
1356
|
* Compare option definitions for global-options compatibility.
|