politty 0.4.0 → 0.4.1
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/completion/index.cjs +4 -3
- package/dist/completion/index.cjs.map +1 -1
- package/dist/completion/index.d.cts +2 -2
- package/dist/completion/index.d.cts.map +1 -1
- package/dist/completion/index.d.ts +2 -2
- package/dist/completion/index.d.ts.map +1 -1
- package/dist/completion/index.js +3 -3
- package/dist/completion/index.js.map +1 -1
- package/dist/docs/index.cjs +2 -2
- package/dist/docs/index.js +2 -2
- package/dist/{extractor-JfoYSoMk.js → extractor-DO-FDKkW.js} +397 -295
- package/dist/extractor-DO-FDKkW.js.map +1 -0
- package/dist/{extractor-CqfDnGKd.cjs → extractor-cjruDqQ2.cjs} +404 -296
- package/dist/extractor-cjruDqQ2.cjs.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/{runner-9dLE13Dv.cjs → runner-0yr2HFay.cjs} +2 -2
- package/dist/{runner-9dLE13Dv.cjs.map → runner-0yr2HFay.cjs.map} +1 -1
- package/dist/{runner-LJRI4haB.js → runner-BoZpJtIR.js} +2 -2
- package/dist/{runner-LJRI4haB.js.map → runner-BoZpJtIR.js.map} +1 -1
- package/dist/schema-extractor-CHiBRT39.d.ts.map +1 -1
- package/dist/{schema-extractor-CP3ar0Wi.js → schema-extractor-DAkmmrOy.js} +5 -1
- package/dist/schema-extractor-DAkmmrOy.js.map +1 -0
- package/dist/schema-extractor-DyfK21m_.d.cts.map +1 -1
- package/dist/{schema-extractor-Cv7ipqLS.cjs → schema-extractor-Mk1MHBkQ.cjs} +5 -1
- package/dist/schema-extractor-Mk1MHBkQ.cjs.map +1 -0
- package/dist/{extractor-DsJ6hYqQ.d.cts → value-completion-resolver-0xf8_07p.d.cts} +56 -11
- package/dist/value-completion-resolver-0xf8_07p.d.cts.map +1 -0
- package/dist/{extractor-CCi4rjSI.d.ts → value-completion-resolver-CUKbibx-.d.ts} +56 -11
- package/dist/value-completion-resolver-CUKbibx-.d.ts.map +1 -0
- package/package.json +6 -5
- package/dist/extractor-CCi4rjSI.d.ts.map +0 -1
- package/dist/extractor-CqfDnGKd.cjs.map +0 -1
- package/dist/extractor-DsJ6hYqQ.d.cts.map +0 -1
- package/dist/extractor-JfoYSoMk.js.map +0 -1
- package/dist/schema-extractor-CP3ar0Wi.js.map +0 -1
- package/dist/schema-extractor-Cv7ipqLS.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_subcommand_router = require('../subcommand-router-4d1Xbp8B.cjs');
|
|
3
|
-
const require_schema_extractor = require('../schema-extractor-
|
|
4
|
-
const require_extractor = require('../extractor-
|
|
3
|
+
const require_schema_extractor = require('../schema-extractor-Mk1MHBkQ.cjs');
|
|
4
|
+
const require_extractor = require('../extractor-cjruDqQ2.cjs');
|
|
5
5
|
let zod = require("zod");
|
|
6
6
|
|
|
7
7
|
//#region src/completion/index.ts
|
|
@@ -159,11 +159,12 @@ exports.createDynamicCompleteCommand = require_extractor.createDynamicCompleteCo
|
|
|
159
159
|
exports.detectShell = detectShell;
|
|
160
160
|
exports.extractCompletionData = require_extractor.extractCompletionData;
|
|
161
161
|
exports.extractPositionals = require_extractor.extractPositionals;
|
|
162
|
-
exports.
|
|
162
|
+
exports.formatForShell = require_extractor.formatForShell;
|
|
163
163
|
exports.generateCandidates = require_extractor.generateCandidates;
|
|
164
164
|
exports.generateCompletion = generateCompletion;
|
|
165
165
|
exports.getSupportedShells = getSupportedShells;
|
|
166
166
|
exports.hasCompleteCommand = require_extractor.hasCompleteCommand;
|
|
167
167
|
exports.parseCompletionContext = require_extractor.parseCompletionContext;
|
|
168
|
+
exports.resolveValueCompletion = require_extractor.resolveValueCompletion;
|
|
168
169
|
exports.withCompletionCommand = withCompletionCommand;
|
|
169
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
|
|
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,yCAAuB,SAAS,QAAQ;EACjD,KAAK,MACH,QAAOC,wCAAsB,SAAS,QAAQ;EAChD,KAAK,OACH,QAAOC,yCAAuB,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,6BACLD,MACG,KAAK;EAAC;EAAQ;EAAO;EAAO,CAAC,CAC7B,UAAU,CACV,SAAS,8CAA8C,EAC1D;EACE,YAAY;EACZ,aAAa;EACb,aAAa;EACd,CACF;CACD,cAAcC,6BAAID,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,+CAA6B,aAAa,oBAAoB;EAC3E;AAGH,QAAOC,gCAAc;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,+CAA6B,gBAAgB,YAAY;EACtE;AAED,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../arg-registry-B4a4Fj7f.cjs";
|
|
2
2
|
import { d as Command, s as AnyCommand } from "../schema-extractor-DyfK21m_.cjs";
|
|
3
|
-
import { _ as
|
|
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-0xf8_07p.cjs";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/completion/index.d.ts
|
|
@@ -73,5 +73,5 @@ interface WithCompletionOptions {
|
|
|
73
73
|
*/
|
|
74
74
|
declare function withCompletionCommand<T extends AnyCommand>(command: T, options?: string | WithCompletionOptions): T;
|
|
75
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 ShellType, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals,
|
|
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
77
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/completion/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/completion/index.ts"],"mappings":";;;;;;;;;iBAoEgB,kBAAA,CACd,OAAA,EAAS,UAAA,EACT,OAAA,EAAS,iBAAA,GACR,gBAAA;;;;iBAgBa,kBAAA,CAAA,GAAsB,SAAA;;;;iBAOtB,WAAA,CAAA,GAAe,SAAA;;;;cAoBzB,oBAAA,EAAoB,CAAA,CAAA,SAAA;;;;;;;;KAkBrB,cAAA,GAAiB,CAAA,CAAE,KAAA,QAAa,oBAAA;;;;;;;;;;;;;;;;iBAiBrB,uBAAA,CACd,WAAA,EAAa,UAAA,EACb,WAAA,YAEC,OAAA,QAAe,oBAAA,EAAsB,cAAA;;;;UA0CvB,qBAAA;EA1CuB;EA4CtC,WAAA;AAAA;;;;;;;;;;AAFF;;;;;AAyBA;;;;;;iBAAgB,qBAAA,WAAgC,UAAA,CAAA,CAC9C,OAAA,EAAS,CAAA,EACT,OAAA,YAAmB,qBAAA,GAClB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../arg-registry-C3GP-5C9.js";
|
|
2
2
|
import { d as Command, s as AnyCommand } from "../schema-extractor-CHiBRT39.js";
|
|
3
|
-
import { _ as
|
|
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-CUKbibx-.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/completion/index.d.ts
|
|
@@ -73,5 +73,5 @@ interface WithCompletionOptions {
|
|
|
73
73
|
*/
|
|
74
74
|
declare function withCompletionCommand<T extends AnyCommand>(command: T, options?: string | WithCompletionOptions): T;
|
|
75
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 ShellType, WithCompletionOptions, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals,
|
|
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
77
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/completion/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/completion/index.ts"],"mappings":";;;;;;;;;iBAoEgB,kBAAA,CACd,OAAA,EAAS,UAAA,EACT,OAAA,EAAS,iBAAA,GACR,gBAAA;;;;iBAgBa,kBAAA,CAAA,GAAsB,SAAA;;;;iBAOtB,WAAA,CAAA,GAAe,SAAA;;;;cAoBzB,oBAAA,EAAoB,CAAA,CAAA,SAAA;;;;;;;;KAkBrB,cAAA,GAAiB,CAAA,CAAE,KAAA,QAAa,oBAAA;;;;;;;;;;;;;;;;iBAiBrB,uBAAA,CACd,WAAA,EAAa,UAAA,EACb,WAAA,YAEC,OAAA,QAAe,oBAAA,EAAsB,cAAA;;;;UA0CvB,qBAAA;EA1CuB;EA4CtC,WAAA;AAAA;;;;;;;;;;AAFF;;;;;AAyBA;;;;;;iBAAgB,qBAAA,WAAgC,UAAA,CAAA,CAC9C,OAAA,EAAS,CAAA,EACT,OAAA,YAAmB,qBAAA,GAClB,CAAA"}
|
package/dist/completion/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as arg } from "../schema-extractor-
|
|
2
|
-
import { a as createDynamicCompleteCommand, c as
|
|
1
|
+
import { a as arg } from "../schema-extractor-DAkmmrOy.js";
|
|
2
|
+
import { a as createDynamicCompleteCommand, c as parseCompletionContext, d as generateCandidates, f as generateBashCompletion, i as generateFishCompletion, l as resolveValueCompletion, n as extractPositionals, o as hasCompleteCommand, p as defineCommand, r as generateZshCompletion, s as formatForShell, t as extractCompletionData, u as CompletionDirective } from "../extractor-DO-FDKkW.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
5
|
//#region src/completion/index.ts
|
|
@@ -151,5 +151,5 @@ function withCompletionCommand(command, options) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
//#endregion
|
|
154
|
-
export { CompletionDirective, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals,
|
|
154
|
+
export { CompletionDirective, createCompletionCommand, createDynamicCompleteCommand, detectShell, extractCompletionData, extractPositionals, formatForShell, generateCandidates, generateCompletion, getSupportedShells, hasCompleteCommand, parseCompletionContext, resolveValueCompletion, withCompletionCommand };
|
|
155
155
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"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
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"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,QAAO,uBAAuB,SAAS,QAAQ;EACjD,KAAK,MACH,QAAO,sBAAsB,SAAS,QAAQ;EAChD,KAAK,OACH,QAAO,uBAAuB,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,uBAAuB,EAAE,OAAO;CACpC,OAAO,IACL,EACG,KAAK;EAAC;EAAQ;EAAO;EAAO,CAAC,CAC7B,UAAU,CACV,SAAS,8CAA8C,EAC1D;EACE,YAAY;EACZ,aAAa;EACb,aAAa;EACd,CACF;CACD,cAAc,IAAI,EAAE,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,YAAY,6BAA6B,aAAa,oBAAoB;EAC3E;AAGH,QAAO,cAAc;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,YAAY,6BAA6B,gBAAgB,YAAY;EACtE;AAED,QAAO"}
|
package/dist/docs/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_subcommand_router = require('../subcommand-router-4d1Xbp8B.cjs');
|
|
3
|
-
const require_schema_extractor = require('../schema-extractor-
|
|
3
|
+
const require_schema_extractor = require('../schema-extractor-Mk1MHBkQ.cjs');
|
|
4
4
|
let zod = require("zod");
|
|
5
5
|
let node_util = require("node:util");
|
|
6
6
|
let node_fs = require("node:fs");
|
|
@@ -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-0yr2HFay.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);
|
package/dist/docs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getExtractedFields, t as extractFields } from "../schema-extractor-
|
|
1
|
+
import { n as getExtractedFields, t as extractFields } from "../schema-extractor-DAkmmrOy.js";
|
|
2
2
|
import { i as createLogCollector, n as resolveLazyCommand } from "../subcommand-router-DtCeT_O9.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -720,7 +720,7 @@ async function executeSingleExample(example, rootCommand, commandPath) {
|
|
|
720
720
|
collector.start();
|
|
721
721
|
let success = true;
|
|
722
722
|
try {
|
|
723
|
-
const { runCommand } = await import("../runner-
|
|
723
|
+
const { runCommand } = await import("../runner-BoZpJtIR.js").then((n) => n.r);
|
|
724
724
|
const result = await runCommand(rootCommand, argv);
|
|
725
725
|
success = result.success;
|
|
726
726
|
if (!result.success && result.error) console.error(result.error.message);
|