politty 0.3.1 → 0.3.2

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/README.md +84 -2
  2. package/dist/{arg-registry-w5mMKJkZ.d.ts → arg-registry-B4a4Fj7f.d.cts} +51 -2
  3. package/dist/arg-registry-B4a4Fj7f.d.cts.map +1 -0
  4. package/dist/{arg-registry-i6SA4l-E.d.cts → arg-registry-C3GP-5C9.d.ts} +51 -2
  5. package/dist/arg-registry-C3GP-5C9.d.ts.map +1 -0
  6. package/dist/augment.d.cts +1 -1
  7. package/dist/augment.d.ts +1 -1
  8. package/dist/completion/index.cjs +23 -460
  9. package/dist/completion/index.cjs.map +1 -1
  10. package/dist/completion/index.d.cts +13 -91
  11. package/dist/completion/index.d.cts.map +1 -1
  12. package/dist/completion/index.d.ts +13 -91
  13. package/dist/completion/index.d.ts.map +1 -1
  14. package/dist/completion/index.js +12 -455
  15. package/dist/completion/index.js.map +1 -1
  16. package/dist/docs/index.cjs +2 -2
  17. package/dist/docs/index.d.cts +2 -1
  18. package/dist/docs/index.d.cts.map +1 -1
  19. package/dist/docs/index.d.ts +2 -1
  20. package/dist/docs/index.d.ts.map +1 -1
  21. package/dist/docs/index.js +2 -2
  22. package/dist/extractor-B7bOwpvP.cjs +970 -0
  23. package/dist/extractor-B7bOwpvP.cjs.map +1 -0
  24. package/dist/extractor-CCi4rjSI.d.ts +238 -0
  25. package/dist/extractor-CCi4rjSI.d.ts.map +1 -0
  26. package/dist/extractor-DsJ6hYqQ.d.cts +238 -0
  27. package/dist/extractor-DsJ6hYqQ.d.cts.map +1 -0
  28. package/dist/extractor-JfoYSoMk.js +898 -0
  29. package/dist/extractor-JfoYSoMk.js.map +1 -0
  30. package/dist/index.cjs +8 -5
  31. package/dist/index.d.cts +5 -3
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.ts +5 -3
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +5 -4
  36. package/dist/{runner-B38UBqhv.cjs → runner-BFKk3Arg.cjs} +25 -13
  37. package/dist/runner-BFKk3Arg.cjs.map +1 -0
  38. package/dist/{runner-CUN50BqK.js → runner-ElQbBn1U.js} +25 -13
  39. package/dist/runner-ElQbBn1U.js.map +1 -0
  40. package/dist/{schema-extractor-B9D3Rf22.cjs → schema-extractor-BU705qpC.cjs} +43 -4
  41. package/dist/schema-extractor-BU705qpC.cjs.map +1 -0
  42. package/dist/{schema-extractor-CXeUTW_Z.d.cts → schema-extractor-CHiBRT39.d.ts} +6 -1
  43. package/dist/schema-extractor-CHiBRT39.d.ts.map +1 -0
  44. package/dist/{schema-extractor-1YXqFSDT.js → schema-extractor-CP3ar0Wi.js} +43 -4
  45. package/dist/schema-extractor-CP3ar0Wi.js.map +1 -0
  46. package/dist/{schema-extractor-Cl_D04BX.d.ts → schema-extractor-DyfK21m_.d.cts} +6 -1
  47. package/dist/schema-extractor-DyfK21m_.d.cts.map +1 -0
  48. package/package.json +6 -6
  49. package/dist/arg-registry-i6SA4l-E.d.cts.map +0 -1
  50. package/dist/arg-registry-w5mMKJkZ.d.ts.map +0 -1
  51. package/dist/command-Bgd-yIwv.cjs +0 -25
  52. package/dist/command-Bgd-yIwv.cjs.map +0 -1
  53. package/dist/command-D-P2Pc3J.js +0 -20
  54. package/dist/command-D-P2Pc3J.js.map +0 -1
  55. package/dist/runner-B38UBqhv.cjs.map +0 -1
  56. package/dist/runner-CUN50BqK.js.map +0 -1
  57. package/dist/schema-extractor-1YXqFSDT.js.map +0 -1
  58. package/dist/schema-extractor-B9D3Rf22.cjs.map +0 -1
  59. package/dist/schema-extractor-CXeUTW_Z.d.cts.map +0 -1
  60. package/dist/schema-extractor-Cl_D04BX.d.ts.map +0 -1
package/README.md CHANGED
@@ -256,8 +256,8 @@ CLI entry point. Handles signals and calls `process.exit()`.
256
256
 
257
257
  ```typescript
258
258
  runMain(command, {
259
- version: "1.0.0", // Displayed with --version flag
260
- argv: process.argv, // Custom argv
259
+ version: "1.0.0", // Displayed with --version flag
260
+ argv: process.argv, // Custom argv
261
261
  });
262
262
  ```
263
263
 
@@ -285,6 +285,88 @@ Attach metadata to an argument.
285
285
  | `description` | `string?` | Argument description |
286
286
  | `placeholder` | `string?` | Placeholder shown in help |
287
287
  | `env` | `string?` | Environment variable name (fallback) |
288
+ | `completion` | `object?` | Shell completion configuration |
289
+
290
+ ## Shell Completion
291
+
292
+ politty provides automatic shell completion generation for bash, zsh, and fish.
293
+
294
+ ### Quick Setup
295
+
296
+ Use `withCompletionCommand` to add completion support to your CLI:
297
+
298
+ ```typescript
299
+ import { defineCommand, runMain, withCompletionCommand } from "politty";
300
+
301
+ const mainCommand = withCompletionCommand(
302
+ defineCommand({
303
+ name: "mycli",
304
+ subCommands: {
305
+ build: buildCommand,
306
+ test: testCommand,
307
+ },
308
+ }),
309
+ );
310
+
311
+ runMain(mainCommand);
312
+ ```
313
+
314
+ Then users can enable completions:
315
+
316
+ ```bash
317
+ # Bash
318
+ eval "$(mycli completion bash)"
319
+
320
+ # Zsh
321
+ eval "$(mycli completion zsh)"
322
+
323
+ # Fish
324
+ mycli completion fish | source
325
+ ```
326
+
327
+ ### Value Completion
328
+
329
+ Define completion hints for arguments:
330
+
331
+ ```typescript
332
+ const command = defineCommand({
333
+ name: "build",
334
+ args: z.object({
335
+ // Auto-detected from z.enum()
336
+ format: arg(z.enum(["json", "yaml", "xml"]), {
337
+ alias: "f",
338
+ description: "Output format",
339
+ }),
340
+
341
+ // File completion
342
+ config: arg(z.string(), {
343
+ completion: { type: "file", extensions: ["json", "yaml"] },
344
+ }),
345
+
346
+ // Directory completion
347
+ outputDir: arg(z.string(), {
348
+ completion: { type: "directory" },
349
+ }),
350
+
351
+ // Custom shell command
352
+ branch: arg(z.string().optional(), {
353
+ completion: {
354
+ custom: { shellCommand: "git branch --format='%(refname:short)'" },
355
+ },
356
+ }),
357
+
358
+ // Static choices
359
+ environment: arg(z.string(), {
360
+ completion: {
361
+ custom: { choices: ["development", "staging", "production"] },
362
+ },
363
+ }),
364
+ }),
365
+ run: (args) => {
366
+ /* ... */
367
+ },
368
+ });
369
+ ```
288
370
 
289
371
  ## Documentation
290
372
 
@@ -1,6 +1,53 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  //#region src/core/arg-registry.d.ts
4
+ /**
5
+ * Built-in completion types
6
+ */
7
+ type CompletionType = "file" | "directory" | "none";
8
+ /**
9
+ * Custom completion specification
10
+ */
11
+ interface CustomCompletion {
12
+ /** Static list of choices for completion */
13
+ choices?: string[];
14
+ /** Shell command to execute for dynamic completion */
15
+ shellCommand?: string;
16
+ }
17
+ /**
18
+ * Completion metadata for an argument
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // File completion with extension filter
23
+ * input: arg(z.string(), {
24
+ * completion: { type: "file", extensions: ["json", "yaml"] }
25
+ * })
26
+ *
27
+ * // Directory completion
28
+ * outputDir: arg(z.string(), {
29
+ * completion: { type: "directory" }
30
+ * })
31
+ *
32
+ * // Custom static choices
33
+ * logLevel: arg(z.string(), {
34
+ * completion: { custom: { choices: ["debug", "info", "warn", "error"] } }
35
+ * })
36
+ *
37
+ * // Dynamic completion from shell command
38
+ * branch: arg(z.string(), {
39
+ * completion: { custom: { shellCommand: "git branch --format='%(refname:short)'" } }
40
+ * })
41
+ * ```
42
+ */
43
+ interface CompletionMeta {
44
+ /** Built-in completion type */
45
+ type?: CompletionType;
46
+ /** Custom completion (takes precedence over type if both specified) */
47
+ custom?: CustomCompletion;
48
+ /** File extension filter (only applies when type is "file") */
49
+ extensions?: string[];
50
+ }
4
51
  /**
5
52
  * Base metadata shared by all argument types
6
53
  */
@@ -26,6 +73,8 @@ interface BaseArgMeta {
26
73
  * ```
27
74
  */
28
75
  env?: string | string[];
76
+ /** Completion configuration for shell tab-completion */
77
+ completion?: CompletionMeta;
29
78
  }
30
79
  /**
31
80
  * Metadata for regular arguments (non-builtin aliases)
@@ -84,5 +133,5 @@ type ValidateArgMeta<M> = M extends {
84
133
  declare function arg<T extends z.ZodType>(schema: T): T;
85
134
  declare function arg<T extends z.ZodType, M extends ArgMeta>(schema: T, meta: ValidateArgMeta<M>): T;
86
135
  //#endregion
87
- export { arg as n, ArgMeta as t };
88
- //# sourceMappingURL=arg-registry-w5mMKJkZ.d.ts.map
136
+ export { arg as a, CustomCompletion as i, CompletionMeta as n, CompletionType as r, ArgMeta as t };
137
+ //# sourceMappingURL=arg-registry-B4a4Fj7f.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arg-registry-B4a4Fj7f.d.cts","names":[],"sources":["../src/core/arg-registry.ts"],"mappings":";;;;;AAKA;KAAY,cAAA;;;;UAKK,gBAAA;EAAgB;EAE/B,OAAA;EAAA;EAEA,YAAA;AAAA;;;;;;;;;;;AAyCF;;;;;;;;;;;;AA6BA;;;;UAzCiB,cAAA;EAiDA;EA/Cf,IAAA,GAAO,cAAA;;EAEP,MAAA,GAAS,gBAAA;EA6CqC;EA3C9C,UAAA;AAAA;;;AAqDF;UA/CiB,WAAA;;EAEf,WAAA;EA6C2D;EA3C3D,UAAA;EA8EkB;EA5ElB,WAAA;EA4EwB;;;;;;;;;;;;;;EA7DxB,GAAA;EAiEO;EA/DP,UAAA,GAAa,cAAA;AAAA;;;;UAME,cAAA,SAAuB,WAAA;EA6DnC;EA3DH,KAAA;AAAA;;;;UAMe,sBAAA,SAA+B,WAAA;EAuDM;EArDpD,KAAA;EAqDkB;EAnDlB,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,6 +1,53 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  //#region src/core/arg-registry.d.ts
4
+ /**
5
+ * Built-in completion types
6
+ */
7
+ type CompletionType = "file" | "directory" | "none";
8
+ /**
9
+ * Custom completion specification
10
+ */
11
+ interface CustomCompletion {
12
+ /** Static list of choices for completion */
13
+ choices?: string[];
14
+ /** Shell command to execute for dynamic completion */
15
+ shellCommand?: string;
16
+ }
17
+ /**
18
+ * Completion metadata for an argument
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // File completion with extension filter
23
+ * input: arg(z.string(), {
24
+ * completion: { type: "file", extensions: ["json", "yaml"] }
25
+ * })
26
+ *
27
+ * // Directory completion
28
+ * outputDir: arg(z.string(), {
29
+ * completion: { type: "directory" }
30
+ * })
31
+ *
32
+ * // Custom static choices
33
+ * logLevel: arg(z.string(), {
34
+ * completion: { custom: { choices: ["debug", "info", "warn", "error"] } }
35
+ * })
36
+ *
37
+ * // Dynamic completion from shell command
38
+ * branch: arg(z.string(), {
39
+ * completion: { custom: { shellCommand: "git branch --format='%(refname:short)'" } }
40
+ * })
41
+ * ```
42
+ */
43
+ interface CompletionMeta {
44
+ /** Built-in completion type */
45
+ type?: CompletionType;
46
+ /** Custom completion (takes precedence over type if both specified) */
47
+ custom?: CustomCompletion;
48
+ /** File extension filter (only applies when type is "file") */
49
+ extensions?: string[];
50
+ }
4
51
  /**
5
52
  * Base metadata shared by all argument types
6
53
  */
@@ -26,6 +73,8 @@ interface BaseArgMeta {
26
73
  * ```
27
74
  */
28
75
  env?: string | string[];
76
+ /** Completion configuration for shell tab-completion */
77
+ completion?: CompletionMeta;
29
78
  }
30
79
  /**
31
80
  * Metadata for regular arguments (non-builtin aliases)
@@ -84,5 +133,5 @@ type ValidateArgMeta<M> = M extends {
84
133
  declare function arg<T extends z.ZodType>(schema: T): T;
85
134
  declare function arg<T extends z.ZodType, M extends ArgMeta>(schema: T, meta: ValidateArgMeta<M>): T;
86
135
  //#endregion
87
- export { arg as n, ArgMeta as t };
88
- //# sourceMappingURL=arg-registry-i6SA4l-E.d.cts.map
136
+ export { arg as a, CustomCompletion as i, CompletionMeta as n, CompletionType as r, ArgMeta as t };
137
+ //# sourceMappingURL=arg-registry-C3GP-5C9.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arg-registry-C3GP-5C9.d.ts","names":[],"sources":["../src/core/arg-registry.ts"],"mappings":";;;;;AAKA;KAAY,cAAA;;;;UAKK,gBAAA;EAAgB;EAE/B,OAAA;EAAA;EAEA,YAAA;AAAA;;;;;;;;;;;AAyCF;;;;;;;;;;;;AA6BA;;;;UAzCiB,cAAA;EAiDA;EA/Cf,IAAA,GAAO,cAAA;;EAEP,MAAA,GAAS,gBAAA;EA6CqC;EA3C9C,UAAA;AAAA;;;AAqDF;UA/CiB,WAAA;;EAEf,WAAA;EA6C2D;EA3C3D,UAAA;EA8EkB;EA5ElB,WAAA;EA4EwB;;;;;;;;;;;;;;EA7DxB,GAAA;EAiEO;EA/DP,UAAA,GAAa,cAAA;AAAA;;;;UAME,cAAA,SAAuB,WAAA;EA6DnC;EA3DH,KAAA;AAAA;;;;UAMe,sBAAA,SAA+B,WAAA;EAuDM;EArDpD,KAAA;EAqDkB;EAnDlB,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,4 +1,4 @@
1
- import { t as ArgMeta } from "./arg-registry-i6SA4l-E.cjs";
1
+ import { t as ArgMeta } from "./arg-registry-B4a4Fj7f.cjs";
2
2
 
3
3
  //#region src/augment.d.ts
4
4
  declare module "zod" {
package/dist/augment.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ArgMeta } from "./arg-registry-w5mMKJkZ.js";
1
+ import { t as ArgMeta } from "./arg-registry-C3GP-5C9.js";
2
2
 
3
3
  //#region src/augment.d.ts
4
4
  declare module "zod" {