@kjanat/dreamcli 1.0.0 → 2.0.0

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 (217) hide show
  1. package/CHANGELOG.md +45 -6
  2. package/LICENSE +1 -1
  3. package/README.md +296 -164
  4. package/dist/core/cli/dispatch.d.mts +85 -0
  5. package/dist/core/cli/dispatch.mjs +1 -0
  6. package/dist/core/cli/index.d.mts +418 -0
  7. package/dist/core/cli/index.mjs +1 -0
  8. package/dist/core/cli/planner.d.mts +143 -0
  9. package/dist/core/cli/planner.mjs +1 -0
  10. package/dist/core/cli/plugin.d.mts +94 -0
  11. package/dist/core/cli/plugin.mjs +1 -0
  12. package/dist/core/cli/propagate.d.mts +39 -0
  13. package/dist/core/cli/propagate.mjs +1 -0
  14. package/dist/core/cli/root-help.d.mts +28 -0
  15. package/dist/core/cli/root-help.mjs +7 -0
  16. package/dist/core/cli/root-surface.d.mts +42 -0
  17. package/dist/core/cli/root-surface.mjs +1 -0
  18. package/dist/core/cli/runtime-preflight.d.mts +149 -0
  19. package/dist/core/cli/runtime-preflight.mjs +1 -0
  20. package/dist/core/completion/index.d.mts +46 -0
  21. package/dist/core/completion/index.mjs +1 -0
  22. package/dist/core/completion/shells/bash.d.mts +24 -0
  23. package/dist/core/completion/shells/bash.mjs +3 -0
  24. package/dist/core/completion/shells/fish.d.mts +20 -0
  25. package/dist/core/completion/shells/fish.mjs +2 -0
  26. package/dist/core/completion/shells/powershell.d.mts +14 -0
  27. package/dist/core/completion/shells/powershell.mjs +2 -0
  28. package/dist/core/completion/shells/shared.d.mts +139 -0
  29. package/dist/core/completion/shells/shared.mjs +1 -0
  30. package/dist/core/completion/shells/zsh.d.mts +24 -0
  31. package/dist/core/completion/shells/zsh.mjs +2 -0
  32. package/dist/core/config/index.d.mts +161 -0
  33. package/dist/core/config/index.mjs +1 -0
  34. package/dist/core/config/package-json.d.mts +68 -0
  35. package/dist/core/config/package-json.mjs +1 -0
  36. package/dist/core/errors/index.d.mts +126 -0
  37. package/dist/core/errors/index.mjs +1 -0
  38. package/dist/core/execution/index.d.mts +49 -0
  39. package/dist/core/execution/index.mjs +1 -0
  40. package/dist/core/help/index.d.mts +49 -0
  41. package/dist/core/help/index.mjs +8 -0
  42. package/dist/core/json-schema/index.d.mts +109 -0
  43. package/dist/core/json-schema/index.mjs +55 -0
  44. package/dist/core/json-schema/meta-descriptions.generated.d.mts +185 -0
  45. package/dist/core/json-schema/meta-descriptions.generated.mjs +28 -0
  46. package/dist/core/output/activity.d.mts +194 -0
  47. package/dist/core/output/activity.mjs +1 -0
  48. package/dist/core/output/contracts.d.mts +88 -0
  49. package/dist/core/output/contracts.mjs +1 -0
  50. package/dist/core/output/display-value.d.mts +19 -0
  51. package/dist/core/output/display-value.mjs +1 -0
  52. package/dist/core/output/index.d.mts +280 -0
  53. package/dist/core/output/index.mjs +2 -0
  54. package/dist/core/output/renderers.d.mts +46 -0
  55. package/dist/core/output/renderers.mjs +1 -0
  56. package/dist/core/output/writer.d.mts +40 -0
  57. package/dist/core/output/writer.mjs +1 -0
  58. package/dist/core/parse/index.d.mts +79 -0
  59. package/dist/core/parse/index.mjs +1 -0
  60. package/dist/core/prompt/index.d.mts +205 -0
  61. package/dist/core/prompt/index.mjs +6 -0
  62. package/dist/core/resolve/args.d.mts +8 -0
  63. package/dist/core/resolve/args.mjs +1 -0
  64. package/dist/core/resolve/coerce.d.mts +22 -0
  65. package/dist/core/resolve/coerce.mjs +1 -0
  66. package/dist/core/resolve/config.d.mts +10 -0
  67. package/dist/core/resolve/config.mjs +1 -0
  68. package/dist/core/resolve/contracts.d.mts +112 -0
  69. package/dist/core/resolve/errors.d.mts +11 -0
  70. package/dist/core/resolve/errors.mjs +2 -0
  71. package/dist/core/resolve/flags.d.mts +10 -0
  72. package/dist/core/resolve/flags.mjs +1 -0
  73. package/dist/core/resolve/index.d.mts +42 -0
  74. package/dist/core/resolve/index.mjs +1 -0
  75. package/dist/core/resolve/property.d.mts +47 -0
  76. package/dist/core/resolve/property.mjs +1 -0
  77. package/dist/core/schema/activity.d.mts +169 -0
  78. package/dist/core/schema/arg.d.mts +559 -0
  79. package/dist/core/schema/arg.mjs +1 -0
  80. package/dist/core/schema/command.d.mts +960 -0
  81. package/dist/core/schema/command.mjs +1 -0
  82. package/dist/core/schema/flag.d.mts +491 -0
  83. package/dist/core/schema/flag.mjs +1 -0
  84. package/dist/core/schema/index.d.mts +8 -0
  85. package/dist/core/schema/middleware.d.mts +122 -0
  86. package/dist/core/schema/middleware.mjs +1 -0
  87. package/dist/core/schema/prompt.d.mts +117 -0
  88. package/dist/core/schema/run.d.mts +171 -0
  89. package/dist/core/schema-dsl/runtime.d.mts +144 -0
  90. package/dist/core/schema-dsl/runtime.mjs +2 -0
  91. package/dist/core/schema-dsl/to-json-schema.d.mts +30 -0
  92. package/dist/core/schema-dsl/to-json-schema.mjs +1 -0
  93. package/dist/core/testkit/index.d.mts +54 -0
  94. package/dist/core/testkit/index.mjs +1 -0
  95. package/dist/index.d.mts +28 -920
  96. package/dist/index.mjs +1 -10
  97. package/dist/runtime/adapter.d.mts +212 -0
  98. package/dist/{adapter-B37d9oia.mjs → runtime/adapter.mjs} +1 -1
  99. package/dist/runtime/auto.d.mts +26 -0
  100. package/dist/runtime/auto.mjs +1 -0
  101. package/dist/runtime/bun.d.mts +28 -0
  102. package/dist/runtime/bun.mjs +1 -0
  103. package/dist/runtime/deno.d.mts +76 -0
  104. package/dist/runtime/deno.mjs +2 -0
  105. package/dist/runtime/detect.d.mts +86 -0
  106. package/dist/runtime/detect.mjs +1 -0
  107. package/dist/runtime/index.d.mts +7 -0
  108. package/dist/runtime/node.d.mts +65 -0
  109. package/dist/runtime/node.mjs +2 -0
  110. package/dist/runtime/paths.d.mts +31 -0
  111. package/dist/runtime/paths.mjs +1 -0
  112. package/dist/runtime/support.d.mts +42 -0
  113. package/dist/runtime/support.mjs +1 -0
  114. package/dist/runtime.d.mts +6 -252
  115. package/dist/runtime.mjs +1 -1
  116. package/dist/testkit.d.mts +5 -24
  117. package/dist/testkit.mjs +1 -1
  118. package/dist/version.d.mts +16 -0
  119. package/dist/version.mjs +1 -0
  120. package/dreamcli.schema.json +338 -0
  121. package/examples/basic.ts +2 -2
  122. package/examples/gh/package.json +7 -11
  123. package/examples/gh/src/commands/auth.ts +2 -2
  124. package/examples/gh/src/commands/issue.ts +4 -4
  125. package/examples/gh/src/commands/pr.ts +4 -4
  126. package/examples/gh/src/docs.ts +11 -0
  127. package/examples/gh/src/lib/auth.ts +1 -1
  128. package/examples/gh/src/main.test.ts +6 -5
  129. package/examples/gh/src/main.ts +8 -6
  130. package/examples/interactive.ts +3 -3
  131. package/examples/json-mode.ts +4 -6
  132. package/examples/middleware.ts +3 -3
  133. package/examples/multi-command.ts +3 -3
  134. package/examples/spinner-progress.ts +5 -5
  135. package/examples/testing.ts +8 -6
  136. package/package.json +70 -44
  137. package/src/core/cli/dispatch.ts +4 -0
  138. package/src/core/cli/index.ts +185 -632
  139. package/src/core/cli/planner.ts +413 -0
  140. package/src/core/cli/plugin.ts +7 -1
  141. package/src/core/cli/propagate.ts +1 -1
  142. package/src/core/cli/runtime-preflight.ts +409 -0
  143. package/src/core/completion/index.ts +15 -9
  144. package/src/core/completion/shells/bash.ts +6 -3
  145. package/src/core/completion/shells/fish.ts +245 -10
  146. package/src/core/completion/shells/powershell.ts +390 -9
  147. package/src/core/completion/shells/shared.ts +4 -4
  148. package/src/core/completion/shells/zsh.ts +12 -7
  149. package/src/core/config/index.ts +7 -4
  150. package/src/core/config/package-json.ts +6 -2
  151. package/src/core/errors/index.ts +23 -8
  152. package/src/core/execution/index.ts +270 -0
  153. package/src/core/help/index.ts +13 -15
  154. package/src/core/json-schema/index.ts +193 -7
  155. package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
  156. package/src/core/output/contracts.ts +194 -0
  157. package/src/core/output/index.ts +47 -82
  158. package/src/core/output/renderers.ts +125 -0
  159. package/src/core/parse/index.ts +39 -21
  160. package/src/core/prompt/index.ts +44 -27
  161. package/src/core/resolve/args.ts +144 -0
  162. package/src/core/resolve/coerce.ts +432 -0
  163. package/src/core/resolve/config.ts +26 -0
  164. package/src/core/resolve/contracts.ts +135 -0
  165. package/src/core/resolve/errors.ts +227 -0
  166. package/src/core/resolve/flags.ts +205 -0
  167. package/src/core/resolve/index.ts +41 -1264
  168. package/src/core/resolve/property.ts +99 -0
  169. package/src/core/schema/activity.ts +3 -0
  170. package/src/core/schema/arg.ts +26 -14
  171. package/src/core/schema/command.ts +265 -38
  172. package/src/core/schema/flag.ts +120 -15
  173. package/src/core/schema/index.ts +11 -2
  174. package/src/core/schema/middleware.ts +6 -6
  175. package/src/core/schema/prompt.ts +9 -1
  176. package/src/core/schema/run.ts +25 -17
  177. package/src/core/schema-dsl/index.ts +109 -0
  178. package/src/core/schema-dsl/parse.ts +262 -0
  179. package/src/core/schema-dsl/runtime.ts +609 -0
  180. package/src/core/schema-dsl/to-json-schema.ts +102 -0
  181. package/src/core/testkit/index.ts +55 -297
  182. package/src/index.ts +10 -4
  183. package/src/runtime/adapter.ts +13 -10
  184. package/src/runtime/auto.ts +3 -3
  185. package/src/runtime/bun.ts +4 -4
  186. package/src/runtime/deno.ts +43 -29
  187. package/src/runtime/detect.ts +4 -1
  188. package/src/runtime/index.ts +1 -1
  189. package/src/runtime/node.ts +43 -21
  190. package/src/runtime/paths.ts +9 -3
  191. package/src/runtime/support.ts +20 -4
  192. package/src/runtime.ts +1 -1
  193. package/src/testkit.ts +10 -8
  194. package/dist/adapter-CCSh5juX.cjs +0 -1
  195. package/dist/adapter-DIwO-q7K.d.mts +0 -3447
  196. package/dist/adapter-DQnxxLiE.d.cts +0 -3447
  197. package/dist/auto-5cjZaF9V.mjs +0 -3
  198. package/dist/auto-B0eSgoDw.cjs +0 -3
  199. package/dist/index.cjs +0 -10
  200. package/dist/index.d.cts +0 -920
  201. package/dist/runtime.cjs +0 -1
  202. package/dist/runtime.d.cts +0 -253
  203. package/dist/testkit-CEDYPvhF.mjs +0 -14
  204. package/dist/testkit-ClIKijxC.cjs +0 -14
  205. package/dist/testkit.cjs +0 -1
  206. package/dist/testkit.d.cts +0 -25
  207. package/examples/gh/tsconfig.json +0 -37
  208. package/examples/tsconfig.json +0 -17
  209. package/src/core/cli/AGENTS.md +0 -72
  210. package/src/core/completion/AGENTS.md +0 -72
  211. package/src/core/completion/completion-test-helpers.ts +0 -48
  212. package/src/core/output/AGENTS.md +0 -69
  213. package/src/core/resolve/AGENTS.md +0 -69
  214. package/src/core/schema/AGENTS.md +0 -61
  215. package/src/core/testkit/AGENTS.md +0 -55
  216. package/src/runtime/AGENTS.md +0 -74
  217. package/src/runtime/test-helpers.ts +0 -40
@@ -0,0 +1,559 @@
1
+ //#region src/core/schema/arg.d.ts
2
+ /**
3
+ * Positional argument schema builder with full type inference.
4
+ *
5
+ * Each factory (`arg.string()`, `arg.number()`, `arg.enum()`, `arg.custom()`) returns an
6
+ * immutable {@linkcode ArgBuilder} whose generic parameter tracks the value type,
7
+ * presence state, and variadic flag through the fluent chain.
8
+ *
9
+ * @module dreamcli/core/schema/arg
10
+ */
11
+ /** All arg presence states as a runtime array. */
12
+ declare const ARG_PRESENCES: readonly ['required', 'optional', 'defaulted'];
13
+ /**
14
+ * Presence describes whether a positional arg is guaranteed to exist when the
15
+ * action handler runs:
16
+ *
17
+ * - `'required'` — must be supplied; error if missing (default)
18
+ * - `'optional'` — may be `undefined` if not supplied
19
+ * - `'defaulted'` — always present (falls back to default value)
20
+ */
21
+ type ArgPresence = (typeof ARG_PRESENCES)[number];
22
+ /**
23
+ * Compile-time state carried through the builder chain.
24
+ */
25
+ interface ArgConfig {
26
+ /** The resolved value type (e.g. `string`, `number`, custom). */
27
+ readonly valueType: unknown;
28
+ /** Whether the arg is required, optional, or has a default. */
29
+ readonly presence: ArgPresence;
30
+ /** Whether this arg consumes remaining positionals. */
31
+ readonly variadic: boolean;
32
+ }
33
+ /**
34
+ * Advanced type helper used by {@linkcode ArgBuilder} modifiers to replace presence.
35
+ * Most consumers rely on inference and never reference this directly.
36
+ */
37
+ type WithArgPresence<C extends ArgConfig, P extends ArgPresence> = {
38
+ readonly valueType: C['valueType'];
39
+ readonly presence: P;
40
+ readonly variadic: C['variadic'];
41
+ };
42
+ /**
43
+ * Advanced type helper used by {@linkcode ArgBuilder.variadic | ArgBuilder.variadic()}.
44
+ * Most consumers rely on inference and never reference this directly.
45
+ */
46
+ type WithVariadic<C extends ArgConfig> = {
47
+ readonly valueType: C['valueType'];
48
+ readonly presence: C['presence'];
49
+ readonly variadic: true;
50
+ };
51
+ /**
52
+ * Compute the final value type from config — this is what handlers receive.
53
+ *
54
+ * Advanced type helper: this powers {@link InferArg} and action-handler
55
+ * inference. Most apps do not need to mention it explicitly.
56
+ *
57
+ * Variadic args always produce an array. Non-variadic:
58
+ * - `'optional'` → `T | undefined`
59
+ * - `'required'` → `T`
60
+ * - `'defaulted'` → `T`
61
+ */
62
+ type ResolvedArgValue<C extends ArgConfig> = C['variadic'] extends true ? C['valueType'][] : C['presence'] extends 'optional' ? C['valueType'] | undefined : C['valueType'];
63
+ /** Extract the resolved value type from an {@linkcode ArgBuilder}. */
64
+ type InferArg<B> = B extends ArgBuilder<infer C extends ArgConfig> ? ResolvedArgValue<C> : never;
65
+ /** Extract resolved value types from a record of builders. */
66
+ type InferArgs<T extends Record<string, ArgBuilder<ArgConfig>>> = { [K in keyof T]: InferArg<T[K]> };
67
+ /** All arg kind discriminators as a runtime array. */
68
+ declare const ARG_KINDS: readonly ['string', 'number', 'enum', 'custom'];
69
+ /** Discriminator for the kind of value an arg accepts. */
70
+ type ArgKind = (typeof ARG_KINDS)[number];
71
+ /** Custom parse function for `arg.custom()`. */
72
+ type ArgParseFn<T> = (raw: string) => T;
73
+ /**
74
+ * The runtime descriptor stored inside every {@linkcode ArgBuilder}. Consumers (parser,
75
+ * help generator) read this to understand the arg's shape without touching
76
+ * generics.
77
+ */
78
+ interface ArgSchema {
79
+ /** What kind of value this arg accepts. */
80
+ readonly kind: ArgKind;
81
+ /** Current presence state. */
82
+ readonly presence: ArgPresence;
83
+ /** Whether this arg consumes all remaining positionals. */
84
+ readonly variadic: boolean;
85
+ /**
86
+ * Whether this arg may read from stdin during resolution.
87
+ * @defaultValue `false`
88
+ */
89
+ readonly stdinMode: boolean;
90
+ /** Runtime default value (if any). */
91
+ readonly defaultValue: unknown;
92
+ /** Human-readable description for help text. */
93
+ readonly description: string | undefined;
94
+ /**
95
+ * Environment variable name for env resolution.
96
+ *
97
+ * When set and the CLI value is absent, the resolver reads this env var
98
+ * and coerces the string to the arg's declared kind.
99
+ *
100
+ * @see {@link ArgBuilder.env} for the builder method.
101
+ */
102
+ readonly envVar: string | undefined;
103
+ /** Allowed literal values when `kind === 'enum'`. */
104
+ readonly enumValues: readonly string[] | undefined;
105
+ /** Custom parse function (only when `kind === 'custom'`). */
106
+ readonly parseFn: ArgParseFn<unknown> | undefined;
107
+ /**
108
+ * Deprecation marker.
109
+ *
110
+ * - `undefined` — not deprecated (default)
111
+ * - `true` — deprecated with no migration message
112
+ * - `string` — deprecated with a reason/migration message
113
+ *
114
+ * When a deprecated arg is used, a warning is emitted to stderr.
115
+ * Help text shows `[deprecated]` or `[deprecated: <reason>]`.
116
+ */
117
+ readonly deprecated: string | true | undefined;
118
+ }
119
+ /**
120
+ * Create a raw {@link ArgSchema} object with sensible defaults.
121
+ *
122
+ * Most consumers should prefer the higher-level {@link arg} factory, which
123
+ * returns an immutable {@link ArgBuilder} with type inference and fluent
124
+ * modifiers. `createArgSchema()` exists for advanced schema composition,
125
+ * targeted tests, or custom builders that need the plain runtime descriptor.
126
+ *
127
+ * `overrides` are shallow-merged on top of the default shape, so callers are
128
+ * responsible for preserving invariants such as variadic ordering and
129
+ * compatible `parseFn` / `kind` combinations.
130
+ *
131
+ * @param kind - Discriminator for the value type this arg accepts.
132
+ * @param overrides - Partial schema fields shallow-merged onto defaults.
133
+ * @returns A fully populated {@link ArgSchema}.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const schema = createArgSchema('custom', {
138
+ * description: 'Hex color',
139
+ * parseFn: (raw) => `#${raw}`,
140
+ * });
141
+ * ```
142
+ */
143
+ declare function createArgSchema(kind: ArgKind, overrides?: Partial<ArgSchema>): ArgSchema;
144
+ /**
145
+ * Immutable positional argument schema builder.
146
+ *
147
+ * The type parameter `C` is a phantom that tracks the value type, presence,
148
+ * and variadic state through the fluent chain. Each modifier returns a **new**
149
+ * builder — the original is never mutated.
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * // Full command with multiple args and modifiers
154
+ * import { command, arg } from '@kjanat/dreamcli';
155
+ *
156
+ * command('deploy')
157
+ * .arg('target', arg.string()
158
+ * .env('DEPLOY_TARGET')
159
+ * .describe('Deploy target'))
160
+ * .arg('port', arg.number()
161
+ * .env('PORT')
162
+ * .default(3000)
163
+ * .describe('Port number'))
164
+ * .arg('files', arg.string()
165
+ * .variadic()
166
+ * .optional()
167
+ * .describe('Extra config files'))
168
+ * .action(({ args }) => {
169
+ * args.target; // string (required, from CLI or $DEPLOY_TARGET)
170
+ * args.port; // number (defaulted, from CLI, $PORT, or 3000)
171
+ * args.files; // string[] (optional variadic)
172
+ * });
173
+ * ```
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * // Type inference
178
+ * const target = arg.string();
179
+ * type T = InferArg<typeof target>; // string
180
+ *
181
+ * const opt = arg.string().optional();
182
+ * type O = InferArg<typeof opt>; // string | undefined
183
+ *
184
+ * const files = arg.string().variadic();
185
+ * type F = InferArg<typeof files>; // string[]
186
+ * ```
187
+ */
188
+ declare class ArgBuilder<C extends ArgConfig> {
189
+ /** @internal Runtime schema descriptor. */
190
+ readonly schema: ArgSchema;
191
+ /**
192
+ * @internal Type brand — exists only in the type system (`declare`
193
+ * produces no runtime property). Used by {@linkcode InferArg} / {@linkcode InferArgs}.
194
+ */
195
+ readonly _config: C;
196
+ /**
197
+ * Create an arg builder from a pre-built schema descriptor.
198
+ *
199
+ * @param schema - Runtime descriptor for this positional argument.
200
+ */
201
+ constructor(schema: ArgSchema);
202
+ /**
203
+ * Mark the arg as required (this is the default for positional args).
204
+ * Produces an error if no value resolves from any configured source
205
+ * (CLI → stdin → env → default).
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * arg.string().required() // explicit, same as default
210
+ *
211
+ * // In a command — omitting <target> causes a ValidationError:
212
+ * command('deploy')
213
+ * .arg('target', arg.string().required().describe('Deploy target'))
214
+ * // $ mycli deploy
215
+ * // Error: Missing required argument <target>
216
+ * ```
217
+ *
218
+ * @returns The builder (for chaining).
219
+ */
220
+ required(): ArgBuilder<WithArgPresence<C, 'required'>>;
221
+ /**
222
+ * Mark the arg as optional. Handlers receive `undefined` when absent.
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * arg.string().optional()
227
+ *
228
+ * // In a command — handler receives `undefined` when omitted:
229
+ * command('greet')
230
+ * .arg('name', arg.string().optional().describe('Who to greet'))
231
+ * .action(({ args }) => {
232
+ * args.name; // string | undefined
233
+ * });
234
+ * // $ mycli greet → args.name is undefined
235
+ * // $ mycli greet Alice → args.name is 'Alice'
236
+ * ```
237
+ *
238
+ * @returns The builder (for chaining).
239
+ */
240
+ optional(): ArgBuilder<WithArgPresence<C, 'optional'>>;
241
+ /**
242
+ * Provide a default value. The arg becomes "always present" — handlers
243
+ * will never see `undefined`.
244
+ *
245
+ * The generic constraint `V extends C['valueType']` ensures the default
246
+ * matches the arg's declared type.
247
+ *
248
+ * Resolution order when extra sources are configured: CLI → stdin → env → **default**.
249
+ *
250
+ * @param value - Fallback used when no CLI value or env var resolves.
251
+ * @returns The builder (for chaining).
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * arg.string().default('production')
256
+ * arg.number().default(3000)
257
+ *
258
+ * // In a command — default kicks in when CLI and env are both absent:
259
+ * command('deploy')
260
+ * .arg('env', arg.string()
261
+ * .env('DEPLOY_ENV')
262
+ * .default('staging')
263
+ * .describe('Target environment'))
264
+ * .action(({ args }) => {
265
+ * args.env; // string (never undefined)
266
+ * });
267
+ * // $ mycli deploy → 'staging' (default)
268
+ * // $ DEPLOY_ENV=prod mycli deploy → 'prod' (env)
269
+ * // $ mycli deploy production → 'production' (CLI)
270
+ * ```
271
+ */
272
+ default<V extends C['valueType']>(value: V): ArgBuilder<WithArgPresence<C, 'defaulted'>>;
273
+ /**
274
+ * Mark this arg as variadic — it consumes all remaining positional
275
+ * arguments. The inferred type becomes `T[]`.
276
+ *
277
+ * A variadic arg must be the last positional in a command.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * arg.string().variadic()
282
+ *
283
+ * // In a command — collects all remaining positionals:
284
+ * command('build')
285
+ * .arg('entry', arg.string().describe('Main entry'))
286
+ * .arg('extras', arg.string().variadic().optional().describe('Extra files'))
287
+ * .action(({ args }) => {
288
+ * args.entry; // string
289
+ * args.extras; // string[]
290
+ * });
291
+ * // $ mycli build main.ts a.ts b.ts
292
+ * // → entry = 'main.ts', extras = ['a.ts', 'b.ts']
293
+ * ```
294
+ *
295
+ * @returns The builder (for chaining).
296
+ */
297
+ variadic(): ArgBuilder<WithVariadic<C>>;
298
+ /**
299
+ * Allow this arg to resolve from stdin when CLI input is missing.
300
+ *
301
+ * Resolution order becomes: CLI value -> stdin -> env -> default.
302
+ * Only one arg per command may enable stdin mode.
303
+ *
304
+ * @returns The builder (for chaining).
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * arg.string().describe('Input text').stdin()
309
+ * // $ echo "hello" | mycli transform → input = 'hello' (from stdin)
310
+ * // $ mycli transform "hello" → input = 'hello' (from CLI)
311
+ * ```
312
+ */
313
+ stdin(): ArgBuilder<C>;
314
+ /**
315
+ * Bind to an environment variable.
316
+ *
317
+ * When the arg is not provided on the CLI, the resolver checks this
318
+ * env var before falling back to the default value. The env string is
319
+ * coerced to the arg's declared kind (passthrough for strings, parsed
320
+ * for numbers, run through `parseFn` for custom args).
321
+ *
322
+ * Resolution order when extra sources are configured: **CLI → stdin → env → default**.
323
+ *
324
+ * Help output shows `[env: VAR]` next to the arg description.
325
+ *
326
+ * @param varName - Environment variable name (e.g. `'DEPLOY_TARGET'`).
327
+ * @returns The builder (for chaining).
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * command('deploy')
332
+ * .arg('target', arg.string().env('DEPLOY_TARGET').describe('Deploy target'))
333
+ * .arg('port', arg.number().env('PORT').default(3000))
334
+ * .action(({ args }) => {
335
+ * console.log(args.target); // from CLI, $DEPLOY_TARGET, or error
336
+ * console.log(args.port); // from CLI, $PORT, or 3000
337
+ * });
338
+ * ```
339
+ */
340
+ env(varName: string): ArgBuilder<C>;
341
+ /**
342
+ * Human-readable description shown in help output.
343
+ *
344
+ * @param description - Text displayed next to the arg in `--help`.
345
+ * @returns The builder (for chaining).
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * arg.string().describe('Deploy target')
350
+ *
351
+ * // Help output:
352
+ * // Arguments:
353
+ * // <target> Deploy target
354
+ * ```
355
+ */
356
+ describe(description: string): ArgBuilder<C>;
357
+ /**
358
+ * Mark this arg as deprecated.
359
+ *
360
+ * When used, a warning is emitted to stderr. Help text shows
361
+ * `[deprecated]` or `[deprecated: <reason>]`.
362
+ *
363
+ * Does not change the arg's type-level config — it's metadata only.
364
+ *
365
+ * @param message - Optional migration reason/guidance.
366
+ * @returns The builder (for chaining).
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * arg.string().deprecated() // generic
371
+ * arg.string().deprecated('use --target flag instead') // with guidance
372
+ *
373
+ * // Help output:
374
+ * // Arguments:
375
+ * // <target> Deploy target [deprecated: use --target flag instead]
376
+ * ```
377
+ */
378
+ deprecated(message?: string): ArgBuilder<C>;
379
+ }
380
+ /**
381
+ * Arg factory functions — the public API for creating positional arguments.
382
+ *
383
+ * Each method returns an {@linkcode ArgBuilder} seeded with the correct {@linkcode ArgKind}
384
+ * and initial type-level config. Chain modifiers (`.optional()`, `.env()`,
385
+ * `.default()`, `.variadic()`, `.stdin()`, `.describe()`, `.deprecated()`) to refine.
386
+ *
387
+ * All args are **required** by default. Resolution order when extra
388
+ * sources are configured: **CLI → stdin → env → default**.
389
+ *
390
+ * @example Overview — all three kinds with common modifier patterns
391
+ * ```ts
392
+ * command('process')
393
+ * // String arg with env fallback
394
+ * .arg('input', arg.string()
395
+ * .env('INPUT_FILE')
396
+ * .describe('Input file path'))
397
+ *
398
+ * // Number arg with env + default
399
+ * .arg('concurrency', arg.number()
400
+ * .env('CONCURRENCY')
401
+ * .default(4)
402
+ * .describe('Worker threads'))
403
+ *
404
+ * // Custom arg — hex color parser with env
405
+ * .arg('color', arg.custom((raw) => {
406
+ * if (!/^#?[0-9a-f]{6}$/i.test(raw)) throw new Error('bad hex');
407
+ * return raw.startsWith('#') ? raw : `#${raw}`;
408
+ * })
409
+ * .env('THEME_COLOR')
410
+ * .optional()
411
+ * .describe('Theme color (hex)'))
412
+ *
413
+ * .action(({ args }) => {
414
+ * args.input; // string (required)
415
+ * args.concurrency; // number (defaulted)
416
+ * args.color; // string | undefined (optional custom)
417
+ * });
418
+ * ```
419
+ */
420
+ interface ArgFactory {
421
+ /**
422
+ * String-valued positional argument. Required by default.
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * arg.string() // required string
427
+ * arg.string().optional() // string | undefined
428
+ * arg.string().env('TARGET') // falls back to $TARGET
429
+ * arg.string().default('production') // always present
430
+ *
431
+ * // In a command:
432
+ * command('deploy')
433
+ * .arg('target', arg.string().env('DEPLOY_TARGET').describe('Deploy target'))
434
+ * ```
435
+ *
436
+ * @returns A required string {@link ArgBuilder}.
437
+ */
438
+ string(): ArgBuilder<{
439
+ readonly valueType: string;
440
+ readonly presence: 'required';
441
+ readonly variadic: false;
442
+ }>;
443
+ /**
444
+ * Number-valued positional argument. Required by default.
445
+ *
446
+ * The parser coerces the raw CLI string to a number and emits a
447
+ * `ParseError` if conversion fails. Env values are coerced the same way.
448
+ *
449
+ * @example
450
+ * ```ts
451
+ * arg.number() // required number
452
+ * arg.number().default(8080) // defaults to 8080
453
+ * arg.number().env('PORT') // falls back to $PORT (coerced)
454
+ *
455
+ * // In a command:
456
+ * command('serve')
457
+ * .arg('port', arg.number().env('PORT').default(3000).describe('Port'))
458
+ * // $ mycli serve 8080 → 8080
459
+ * // $ PORT=9090 mycli serve → 9090
460
+ * // $ mycli serve → 3000
461
+ * ```
462
+ *
463
+ * @returns A required number {@link ArgBuilder}.
464
+ */
465
+ number(): ArgBuilder<{
466
+ readonly valueType: number;
467
+ readonly presence: 'required';
468
+ readonly variadic: false;
469
+ }>;
470
+ /**
471
+ * Enum-valued positional argument. Required by default.
472
+ *
473
+ * Accepts only the listed string literals. The inferred type is the
474
+ * union of those literals (e.g. `'us' | 'eu' | 'ap'`), not `string`.
475
+ * Invalid values produce a `ParseError` listing allowed options.
476
+ *
477
+ * @param values - Non-empty tuple of allowed string values.
478
+ * @returns A required enum {@link ArgBuilder} typed to the union of `values`.
479
+ *
480
+ * @example
481
+ * ```ts
482
+ * arg.enum(['us', 'eu', 'ap']) // required, 'us' | 'eu' | 'ap'
483
+ * arg.enum(['dev', 'prod']).default('dev') // defaulted
484
+ * arg.enum(['json', 'csv']).optional() // 'json' | 'csv' | undefined
485
+ *
486
+ * // In a command:
487
+ * command('deploy')
488
+ * .arg('region', arg.enum(['us', 'eu', 'ap']).env('REGION').describe('Target region'))
489
+ * // $ mycli deploy us → 'us'
490
+ * // $ mycli deploy invalid → ParseError: Allowed: us, eu, ap
491
+ * ```
492
+ */
493
+ enum<const T extends readonly [string, ...string[]]>(values: T): ArgBuilder<{
494
+ readonly valueType: T[number];
495
+ readonly presence: 'required';
496
+ readonly variadic: false;
497
+ }>;
498
+ /**
499
+ * Custom-parsed positional argument. Required by default.
500
+ *
501
+ * The parse function receives the raw string and must return a value of
502
+ * type `T`. Throw an `Error` (or `ParseError`) to signal invalid input.
503
+ * The same parse function is used for both CLI and env values.
504
+ *
505
+ * @param parseFn - Converts the raw CLI string to `T`.
506
+ * @returns A required custom {@link ArgBuilder} typed to the return of `parseFn`.
507
+ *
508
+ * @example
509
+ * ```ts
510
+ * arg.custom((raw) => Number.parseInt(raw, 16))
511
+ * // inferred type: number
512
+ *
513
+ * // In a command — parse hex color from CLI or $COLOR:
514
+ * command('theme')
515
+ * .arg('color', arg.custom((raw) => {
516
+ * if (!/^[0-9a-f]{6}$/i.test(raw)) throw new Error('Expected 6-digit hex');
517
+ * return `#${raw}`;
518
+ * }).env('COLOR').describe('Hex color code'))
519
+ * // $ mycli theme ff6600 → '#ff6600'
520
+ * // $ COLOR=aabbcc mycli theme → '#aabbcc'
521
+ * ```
522
+ */
523
+ custom<T>(parseFn: ArgParseFn<T>): ArgBuilder<{
524
+ readonly valueType: T;
525
+ readonly presence: 'required';
526
+ readonly variadic: false;
527
+ }>;
528
+ }
529
+ /**
530
+ * Positional argument schema factory.
531
+ *
532
+ * Entry point for defining args on a command. Use `arg.<kind>()` to create
533
+ * an {@linkcode ArgBuilder}, then chain modifiers and pass the result to
534
+ * `command().arg(name, builder)`.
535
+ *
536
+ * Four kinds are available:
537
+ * - `arg.string()` — raw string (most common)
538
+ * - `arg.number()` — parsed to number, errors on NaN
539
+ * - `arg.enum(values)` — constrained to listed literals
540
+ * - `arg.custom(fn)` — arbitrary parse function, infers return type
541
+ *
542
+ * @example
543
+ * ```ts
544
+ * import { command, arg } from '@kjanat/dreamcli';
545
+ *
546
+ * command('deploy')
547
+ * .arg('target', arg.string().env('DEPLOY_TARGET').describe('Where to deploy'))
548
+ * .arg('port', arg.number().env('PORT').default(3000))
549
+ * .action(({ args }) => {
550
+ * console.log(`Deploying to ${args.target} on port ${args.port}`);
551
+ * });
552
+ *
553
+ * // $ mycli deploy production 8080 → target='production', port=8080
554
+ * // $ DEPLOY_TARGET=staging mycli deploy → target='staging', port=3000
555
+ * ```
556
+ */
557
+ declare const arg: ArgFactory;
558
+ //#endregion
559
+ export { ARG_KINDS, ARG_PRESENCES, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type InferArg, type InferArgs, type ResolvedArgValue, type WithArgPresence, type WithVariadic, arg, createArgSchema };
@@ -0,0 +1 @@
1
+ function e(e,t){return{kind:e,presence:`required`,variadic:!1,stdinMode:!1,defaultValue:void 0,description:void 0,envVar:void 0,enumValues:void 0,parseFn:void 0,deprecated:void 0,...t}}var t=class e{schema;constructor(e){this.schema=e}required(){return new e({...this.schema,presence:`required`})}optional(){return new e({...this.schema,presence:`optional`})}default(t){return new e({...this.schema,presence:`defaulted`,defaultValue:t})}variadic(){return new e({...this.schema,variadic:!0})}stdin(){return new e({...this.schema,stdinMode:!0})}env(t){return new e({...this.schema,envVar:t})}describe(t){return new e({...this.schema,description:t})}deprecated(t){return new e({...this.schema,deprecated:t??!0})}};const n={string(){return new t(e(`string`))},number(){return new t(e(`number`))},enum(n){return new t(e(`enum`,{enumValues:n}))},custom(n){return new t(e(`custom`,{parseFn:n}))}};export{t as ArgBuilder,n as arg,e as createArgSchema};