@kjanat/dreamcli 2.5.0 → 3.0.0-rc.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.
- package/CHANGELOG.md +153 -1
- package/README.md +9 -2
- package/dist/core/cli/dispatch.mjs +214 -1
- package/dist/core/cli/help-links.mjs +41 -1
- package/dist/core/cli/index.d.mts +109 -16
- package/dist/core/cli/index.mjs +901 -1
- package/dist/core/cli/planner.d.mts +27 -5
- package/dist/core/cli/planner.mjs +300 -1
- package/dist/core/cli/plugin.mjs +41 -1
- package/dist/core/cli/propagate.mjs +57 -1
- package/dist/core/cli/root-help.d.mts +16 -2
- package/dist/core/cli/root-help.mjs +208 -6
- package/dist/core/cli/root-surface.d.mts +18 -3
- package/dist/core/cli/root-surface.mjs +27 -1
- package/dist/core/cli/runtime-preflight.d.mts +16 -1
- package/dist/core/cli/runtime-preflight.mjs +168 -1
- package/dist/core/completion/index.d.mts +32 -1
- package/dist/core/completion/index.mjs +90 -1
- package/dist/core/completion/shells/bash.mjs +304 -3
- package/dist/core/completion/shells/fish.mjs +159 -2
- package/dist/core/completion/shells/powershell.mjs +353 -2
- package/dist/core/completion/shells/shared.d.mts +10 -0
- package/dist/core/completion/shells/shared.mjs +154 -1
- package/dist/core/completion/shells/zsh.mjs +244 -2
- package/dist/core/config/index.mjs +246 -1
- package/dist/core/config/package-json.mjs +385 -3
- package/dist/core/errors/index.mjs +87 -1
- package/dist/core/execution/index.mjs +189 -1
- package/dist/core/help/ansi.mjs +122 -2
- package/dist/core/help/index.d.mts +45 -1
- package/dist/core/help/index.mjs +329 -7
- package/dist/core/json-schema/index.mjs +487 -9
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +38 -38
- package/dist/core/json-schema/meta-descriptions.generated.mjs +93 -28
- package/dist/core/output/activity.mjs +452 -1
- package/dist/core/output/bind.mjs +56 -1
- package/dist/core/output/contracts.mjs +57 -1
- package/dist/core/output/display-value.mjs +32 -1
- package/dist/core/output/index.d.mts +21 -0
- package/dist/core/output/index.mjs +442 -2
- package/dist/core/output/renderers.mjs +46 -1
- package/dist/core/output/writer.mjs +12 -1
- package/dist/core/parse/index.d.mts +15 -1
- package/dist/core/parse/index.mjs +555 -1
- package/dist/core/prompt/index.d.mts +11 -4
- package/dist/core/prompt/index.mjs +348 -6
- package/dist/core/resolve/args.mjs +105 -1
- package/dist/core/resolve/coerce.mjs +279 -1
- package/dist/core/resolve/config.mjs +19 -1
- package/dist/core/resolve/errors.mjs +140 -2
- package/dist/core/resolve/flags.mjs +196 -1
- package/dist/core/resolve/index.mjs +85 -1
- package/dist/core/resolve/property.d.mts +2 -1
- package/dist/core/resolve/property.mjs +45 -1
- package/dist/core/schema/arg.d.mts +90 -10
- package/dist/core/schema/arg.mjs +463 -1
- package/dist/core/schema/command.d.mts +21 -1
- package/dist/core/schema/command.mjs +712 -1
- package/dist/core/schema/flag.d.mts +92 -2
- package/dist/core/schema/flag.mjs +453 -1
- package/dist/core/schema/index.d.mts +2 -1
- package/dist/core/schema/middleware.mjs +41 -1
- package/dist/core/schema/number-constraints.d.mts +96 -0
- package/dist/core/schema/number-constraints.mjs +60 -0
- package/dist/core/schema/prompt.d.mts +15 -0
- package/dist/core/schema/run.d.mts +4 -4
- package/dist/core/schema-dsl/runtime.mjs +271 -2
- package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
- package/dist/core/testkit/index.d.mts +9 -5
- package/dist/core/testkit/index.mjs +83 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +22 -1
- package/dist/runtime/adapter.mjs +82 -1
- package/dist/runtime/auto.mjs +46 -1
- package/dist/runtime/bun.mjs +28 -1
- package/dist/runtime/deno.mjs +217 -2
- package/dist/runtime/detect.mjs +45 -1
- package/dist/runtime/node.mjs +169 -2
- package/dist/runtime/paths.mjs +48 -1
- package/dist/runtime.mjs +7 -1
- package/dist/strings.mjs +22 -1
- package/dist/testkit.mjs +5 -1
- package/dist/version.mjs +7 -1
- package/examples/basic.ts +5 -1
- package/examples/gh/package.json +2 -7
- package/examples/pwsh-demo/package.json +1 -7
- package/examples/pwsh-demo/src/main.test.ts +1 -4
- package/examples/pwsh-demo/src/main.ts +14 -4
- package/examples/transport-launcher.ts +85 -0
- package/package.json +23 -41
- package/dist/runtime/support.d.mts +0 -42
- package/dist/runtime/support.mjs +0 -1
- package/src/core/cli/dispatch.ts +0 -349
- package/src/core/cli/help-links.ts +0 -82
- package/src/core/cli/index.ts +0 -1413
- package/src/core/cli/planner.ts +0 -487
- package/src/core/cli/plugin.ts +0 -117
- package/src/core/cli/propagate.ts +0 -97
- package/src/core/cli/root-help.ts +0 -252
- package/src/core/cli/root-surface.ts +0 -74
- package/src/core/cli/runtime-preflight.ts +0 -438
- package/src/core/completion/index.ts +0 -88
- package/src/core/completion/shells/bash.ts +0 -459
- package/src/core/completion/shells/fish.ts +0 -259
- package/src/core/completion/shells/powershell.ts +0 -439
- package/src/core/completion/shells/shared.ts +0 -283
- package/src/core/completion/shells/zsh.ts +0 -381
- package/src/core/config/index.ts +0 -417
- package/src/core/config/package-json.ts +0 -560
- package/src/core/errors/index.ts +0 -193
- package/src/core/execution/index.ts +0 -268
- package/src/core/help/ansi.ts +0 -144
- package/src/core/help/index.ts +0 -516
- package/src/core/json-schema/index.ts +0 -891
- package/src/core/json-schema/meta-descriptions.generated.ts +0 -185
- package/src/core/output/activity.ts +0 -575
- package/src/core/output/bind.ts +0 -59
- package/src/core/output/contracts.ts +0 -194
- package/src/core/output/display-value.ts +0 -48
- package/src/core/output/index.ts +0 -704
- package/src/core/output/renderers.ts +0 -125
- package/src/core/output/writer.ts +0 -46
- package/src/core/parse/index.ts +0 -681
- package/src/core/prompt/index.ts +0 -583
- package/src/core/resolve/args.ts +0 -144
- package/src/core/resolve/coerce.ts +0 -432
- package/src/core/resolve/config.ts +0 -26
- package/src/core/resolve/contracts.ts +0 -135
- package/src/core/resolve/errors.ts +0 -227
- package/src/core/resolve/flags.ts +0 -255
- package/src/core/resolve/index.ts +0 -108
- package/src/core/resolve/property.ts +0 -99
- package/src/core/schema/activity.ts +0 -240
- package/src/core/schema/arg.ts +0 -719
- package/src/core/schema/command.ts +0 -1498
- package/src/core/schema/flag.ts +0 -801
- package/src/core/schema/index.ts +0 -91
- package/src/core/schema/middleware.ts +0 -171
- package/src/core/schema/prompt.ts +0 -156
- package/src/core/schema/run.ts +0 -198
- package/src/core/schema-dsl/index.ts +0 -109
- package/src/core/schema-dsl/parse.ts +0 -262
- package/src/core/schema-dsl/runtime.ts +0 -609
- package/src/core/schema-dsl/to-json-schema.ts +0 -102
- package/src/core/testkit/index.ts +0 -123
- package/src/index.ts +0 -179
- package/src/runtime/adapter.ts +0 -303
- package/src/runtime/auto.ts +0 -110
- package/src/runtime/bun.ts +0 -55
- package/src/runtime/deno.ts +0 -369
- package/src/runtime/detect.ts +0 -105
- package/src/runtime/index.ts +0 -21
- package/src/runtime/node-builtins.d.ts +0 -27
- package/src/runtime/node.ts +0 -300
- package/src/runtime/paths.ts +0 -64
- package/src/runtime/support.ts +0 -135
- package/src/runtime.ts +0 -31
- package/src/strings.ts +0 -34
- package/src/testkit.ts +0 -25
- package/src/version.ts +0 -20
|
@@ -1 +1,85 @@
|
|
|
1
|
-
import{isValidationError
|
|
1
|
+
import { isValidationError } from "../errors/index.mjs";
|
|
2
|
+
import { collectValidationErrors, isNonEmpty, throwAggregatedErrors } from "./errors.mjs";
|
|
3
|
+
import { resolveArgs } from "./args.mjs";
|
|
4
|
+
import { resolveFlags } from "./flags.mjs";
|
|
5
|
+
//#region src/core/resolve/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Resolution chain: CLI -> env -> config -> prompt -> default.
|
|
8
|
+
*
|
|
9
|
+
* v0.1 implemented: **CLI parsed value -> default value**.
|
|
10
|
+
* v0.2 adds: **env variable resolution** and **config object resolution**
|
|
11
|
+
* between CLI and default.
|
|
12
|
+
* v0.3 adds: **prompt resolution** between config and default.
|
|
13
|
+
*
|
|
14
|
+
* The resolver takes raw {@linkcode ParseResult} (from the parser) and a
|
|
15
|
+
* {@linkcode CommandSchema}, applies the resolution chain, and validates
|
|
16
|
+
* that all required flags/args are present. On success it returns a
|
|
17
|
+
* {@linkcode ResolveResult} with fully resolved values; on failure it throws
|
|
18
|
+
* {@linkcode ValidationError}.
|
|
19
|
+
*
|
|
20
|
+
* @module dreamcli/core/resolve
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Resolve parsed values against a command schema.
|
|
24
|
+
*
|
|
25
|
+
* Low-level API: most applications should rely on `cli().run()`, `.execute()`,
|
|
26
|
+
* or `runCommand()`, which already call {@linkcode resolve} at the right time.
|
|
27
|
+
* Reach for this function when testing precedence rules directly or building
|
|
28
|
+
* custom execution flows around {@linkcode CommandSchema}.
|
|
29
|
+
*
|
|
30
|
+
* Resolution order:
|
|
31
|
+
* 1. CLI parsed value (from {@linkcode ParseResult})
|
|
32
|
+
* 2. Env variable (from {@linkcode ResolveOptions.env}, if flag declares `envVar`)
|
|
33
|
+
* 3. Config value (from {@linkcode ResolveOptions.config}, if flag declares `configPath`)
|
|
34
|
+
* 4. Prompt (from {@linkcode ResolveOptions.prompter}, if flag declares `prompt`)
|
|
35
|
+
* 5. Default value (from schema)
|
|
36
|
+
*
|
|
37
|
+
* After resolution, validates that all required flags and args have
|
|
38
|
+
* a value. Collects **all** validation errors before throwing, so the
|
|
39
|
+
* user sees every missing field at once.
|
|
40
|
+
*
|
|
41
|
+
* @param schema - The command schema defining flags and args
|
|
42
|
+
* @param parsed - Raw parsed values from the parser
|
|
43
|
+
* @param options - External state for the resolution chain
|
|
44
|
+
* @returns Fully resolved flag and arg values
|
|
45
|
+
* @throws {@linkcode ValidationError} if any required flag or arg is missing,
|
|
46
|
+
* or if an env/config value fails coercion
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const parsed = parse(deploy.schema, ['production']);
|
|
51
|
+
* const resolved = await resolve(deploy.schema, parsed, {
|
|
52
|
+
* env: { DEPLOY_REGION: 'eu' },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
async function resolve(schema, parsed, options) {
|
|
57
|
+
const stdinData = options?.stdinData;
|
|
58
|
+
const env = options?.env ?? {};
|
|
59
|
+
const config = options?.config ?? {};
|
|
60
|
+
const prompter = options?.prompter;
|
|
61
|
+
const deprecations = [];
|
|
62
|
+
let flags = {};
|
|
63
|
+
let args = {};
|
|
64
|
+
const errors = [];
|
|
65
|
+
try {
|
|
66
|
+
flags = await resolveFlags(schema.flags, parsed.flags, env, config, prompter, schema.interactive, deprecations);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (!isValidationError(error)) throw error;
|
|
69
|
+
errors.push(...collectValidationErrors(error));
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
args = resolveArgs(schema.args, parsed.args, stdinData, env, deprecations);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
if (!isValidationError(error)) throw error;
|
|
75
|
+
errors.push(...collectValidationErrors(error));
|
|
76
|
+
}
|
|
77
|
+
if (isNonEmpty(errors)) throwAggregatedErrors(errors);
|
|
78
|
+
return {
|
|
79
|
+
flags,
|
|
80
|
+
args,
|
|
81
|
+
deprecations
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { resolve };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { NumberConstraints } from "../schema/number-constraints.mjs";
|
|
1
2
|
import { ArgSchema } from "../schema/arg.mjs";
|
|
2
3
|
import { FlagSchema } from "../schema/flag.mjs";
|
|
3
|
-
|
|
4
4
|
//#region src/core/resolve/property.d.ts
|
|
5
5
|
/** Flag/arg kinds that share a common coercion path. */
|
|
6
6
|
declare const SHARED_PROPERTY_MODEL_KINDS: readonly ['string', 'number', 'enum', 'custom'];
|
|
@@ -11,6 +11,7 @@ type SharedPropertySchema = {
|
|
|
11
11
|
readonly kind: 'string';
|
|
12
12
|
} | {
|
|
13
13
|
readonly kind: 'number';
|
|
14
|
+
readonly numberConstraints: NumberConstraints | undefined;
|
|
14
15
|
} | {
|
|
15
16
|
readonly kind: 'enum';
|
|
16
17
|
readonly enumValues: readonly string[] | undefined;
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/core/resolve/property.ts
|
|
2
|
+
/** Extract the shared coercion slice from a flag schema, or `undefined` for boolean/array (handled separately). */
|
|
3
|
+
function toSharedFlagPropertySchema(schema) {
|
|
4
|
+
switch (schema.kind) {
|
|
5
|
+
case "string": return { kind: "string" };
|
|
6
|
+
case "number": return {
|
|
7
|
+
kind: "number",
|
|
8
|
+
numberConstraints: schema.numberConstraints
|
|
9
|
+
};
|
|
10
|
+
case "enum": return {
|
|
11
|
+
kind: "enum",
|
|
12
|
+
enumValues: schema.enumValues
|
|
13
|
+
};
|
|
14
|
+
case "custom": return schema.parseFn === void 0 ? { kind: "custom" } : {
|
|
15
|
+
kind: "custom",
|
|
16
|
+
parseFn: schema.parseFn
|
|
17
|
+
};
|
|
18
|
+
case "boolean":
|
|
19
|
+
case "array": return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Extract the shared coercion slice from an arg schema (all arg kinds are shared). */
|
|
23
|
+
function toSharedArgPropertySchema(schema) {
|
|
24
|
+
switch (schema.kind) {
|
|
25
|
+
case "string": return { kind: "string" };
|
|
26
|
+
case "number": return {
|
|
27
|
+
kind: "number",
|
|
28
|
+
numberConstraints: schema.numberConstraints
|
|
29
|
+
};
|
|
30
|
+
case "enum": return {
|
|
31
|
+
kind: "enum",
|
|
32
|
+
enumValues: schema.enumValues
|
|
33
|
+
};
|
|
34
|
+
case "custom": {
|
|
35
|
+
if (schema.parseFn === void 0) return { kind: "custom" };
|
|
36
|
+
const parseFn = schema.parseFn;
|
|
37
|
+
return {
|
|
38
|
+
kind: "custom",
|
|
39
|
+
parseFn: (raw) => parseFn(typeof raw === "string" ? raw : String(raw))
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { toSharedArgPropertySchema, toSharedFlagPropertySchema };
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
+
import { NumberConstraints } from "./number-constraints.mjs";
|
|
2
|
+
|
|
1
3
|
//#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
4
|
/** All arg presence states as a runtime array. */
|
|
12
5
|
declare const ARG_PRESENCES: readonly ['required', 'optional', 'defaulted'];
|
|
13
6
|
/**
|
|
@@ -29,6 +22,8 @@ interface ArgConfig {
|
|
|
29
22
|
readonly presence: ArgPresence;
|
|
30
23
|
/** Whether this arg consumes remaining positionals. */
|
|
31
24
|
readonly variadic: boolean;
|
|
25
|
+
/** The runtime kind discriminator, mirroring {@link ArgKind}. */
|
|
26
|
+
readonly argKind: ArgKind;
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
* Advanced type helper used by {@linkcode ArgBuilder} modifiers to replace presence.
|
|
@@ -38,6 +33,7 @@ type WithArgPresence<C extends ArgConfig, P extends ArgPresence> = {
|
|
|
38
33
|
readonly valueType: C['valueType'];
|
|
39
34
|
readonly presence: P;
|
|
40
35
|
readonly variadic: C['variadic'];
|
|
36
|
+
readonly argKind: C['argKind'];
|
|
41
37
|
};
|
|
42
38
|
/**
|
|
43
39
|
* Advanced type helper used by {@linkcode ArgBuilder.variadic | ArgBuilder.variadic()}.
|
|
@@ -47,6 +43,7 @@ type WithVariadic<C extends ArgConfig> = {
|
|
|
47
43
|
readonly valueType: C['valueType'];
|
|
48
44
|
readonly presence: C['presence'];
|
|
49
45
|
readonly variadic: true;
|
|
46
|
+
readonly argKind: C['argKind'];
|
|
50
47
|
};
|
|
51
48
|
/**
|
|
52
49
|
* Compute the final value type from config — this is what handlers receive.
|
|
@@ -102,6 +99,13 @@ interface ArgSchema {
|
|
|
102
99
|
readonly envVar: string | undefined;
|
|
103
100
|
/** Allowed literal values when `kind === 'enum'`. */
|
|
104
101
|
readonly enumValues: readonly string[] | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Numeric constraints when `kind === 'number'` (`undefined` otherwise).
|
|
104
|
+
*
|
|
105
|
+
* Enforced at the parse and resolution boundaries. `finite` defaults to
|
|
106
|
+
* `true`, so `Infinity` is rejected even when no constraints object is set.
|
|
107
|
+
*/
|
|
108
|
+
readonly numberConstraints: NumberConstraints | undefined;
|
|
105
109
|
/** Custom parse function (only when `kind === 'custom'`). */
|
|
106
110
|
readonly parseFn: ArgParseFn<unknown> | undefined;
|
|
107
111
|
/**
|
|
@@ -376,6 +380,71 @@ declare class ArgBuilder<C extends ArgConfig> {
|
|
|
376
380
|
* ```
|
|
377
381
|
*/
|
|
378
382
|
deprecated(message?: string): ArgBuilder<C>;
|
|
383
|
+
/**
|
|
384
|
+
* Require an integer value. Composes with other numeric constraints.
|
|
385
|
+
*
|
|
386
|
+
* @param value - Whether to require an integer.
|
|
387
|
+
* @defaultValue `true`
|
|
388
|
+
* @returns The builder (for chaining).
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* arg.number().int() // rejects 3.7, accepts 3
|
|
393
|
+
* arg.number({ int: true }).int(false) // re-allows non-integers
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
int(this: ArgBuilder<C & {
|
|
397
|
+
readonly argKind: 'number';
|
|
398
|
+
}>, value?: boolean): ArgBuilder<C>;
|
|
399
|
+
/**
|
|
400
|
+
* Set an inclusive lower bound. Composes with other numeric constraints;
|
|
401
|
+
* a later call overrides an earlier `min` (including one from the options
|
|
402
|
+
* object).
|
|
403
|
+
*
|
|
404
|
+
* @param value - Inclusive minimum.
|
|
405
|
+
* @returns The builder (for chaining).
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* arg.number().min(0) // rejects -1, accepts 0
|
|
410
|
+
* arg.number({ min: 0 }).min(5) // effective min is 5
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
min(this: ArgBuilder<C & {
|
|
414
|
+
readonly argKind: 'number';
|
|
415
|
+
}>, value: number): ArgBuilder<C>;
|
|
416
|
+
/**
|
|
417
|
+
* Set an inclusive upper bound. Composes with other numeric constraints;
|
|
418
|
+
* a later call overrides an earlier `max`.
|
|
419
|
+
*
|
|
420
|
+
* @param value - Inclusive maximum.
|
|
421
|
+
* @returns The builder (for chaining).
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* arg.number().max(100) // rejects 101, accepts 100
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
max(this: ArgBuilder<C & {
|
|
429
|
+
readonly argKind: 'number';
|
|
430
|
+
}>, value: number): ArgBuilder<C>;
|
|
431
|
+
/**
|
|
432
|
+
* Require (or, with `false`, allow) a finite value. Finiteness is enforced
|
|
433
|
+
* by default, so this is mainly used as `.finite(false)` to re-allow
|
|
434
|
+
* `Infinity` / `-Infinity`.
|
|
435
|
+
*
|
|
436
|
+
* @param allow - Whether to require a finite value.
|
|
437
|
+
* @defaultValue `true`
|
|
438
|
+
* @returns The builder (for chaining).
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* arg.number().finite(false) // accepts Infinity
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
finite(this: ArgBuilder<C & {
|
|
446
|
+
readonly argKind: 'number';
|
|
447
|
+
}>, allow?: boolean): ArgBuilder<C>;
|
|
379
448
|
}
|
|
380
449
|
/**
|
|
381
450
|
* Arg factory functions — the public API for creating positional arguments.
|
|
@@ -439,6 +508,7 @@ interface ArgFactory {
|
|
|
439
508
|
readonly valueType: string;
|
|
440
509
|
readonly presence: 'required';
|
|
441
510
|
readonly variadic: false;
|
|
511
|
+
readonly argKind: 'string';
|
|
442
512
|
}>;
|
|
443
513
|
/**
|
|
444
514
|
* Number-valued positional argument. Required by default.
|
|
@@ -460,12 +530,20 @@ interface ArgFactory {
|
|
|
460
530
|
* // $ mycli serve → 3000
|
|
461
531
|
* ```
|
|
462
532
|
*
|
|
533
|
+
* Constraints are enforced at the parse and resolution boundaries and also
|
|
534
|
+
* compose via chained methods (`.int()`, `.min()`, `.max()`, `.finite()`),
|
|
535
|
+
* which override values set here. The resolved value type stays `number`.
|
|
536
|
+
*
|
|
537
|
+
* @param constraints - Optional numeric constraints. `finite` defaults to
|
|
538
|
+
* `true`, so `Infinity` / `-Infinity` are rejected unless `finite: false`.
|
|
539
|
+
* @defaultValue `undefined` (finite-only, no bounds, non-integer allowed)
|
|
463
540
|
* @returns A required number {@link ArgBuilder}.
|
|
464
541
|
*/
|
|
465
|
-
number(): ArgBuilder<{
|
|
542
|
+
number(constraints?: NumberConstraints): ArgBuilder<{
|
|
466
543
|
readonly valueType: number;
|
|
467
544
|
readonly presence: 'required';
|
|
468
545
|
readonly variadic: false;
|
|
546
|
+
readonly argKind: 'number';
|
|
469
547
|
}>;
|
|
470
548
|
/**
|
|
471
549
|
* Enum-valued positional argument. Required by default.
|
|
@@ -494,6 +572,7 @@ interface ArgFactory {
|
|
|
494
572
|
readonly valueType: T[number];
|
|
495
573
|
readonly presence: 'required';
|
|
496
574
|
readonly variadic: false;
|
|
575
|
+
readonly argKind: 'enum';
|
|
497
576
|
}>;
|
|
498
577
|
/**
|
|
499
578
|
* Custom-parsed positional argument. Required by default.
|
|
@@ -524,6 +603,7 @@ interface ArgFactory {
|
|
|
524
603
|
readonly valueType: T;
|
|
525
604
|
readonly presence: 'required';
|
|
526
605
|
readonly variadic: false;
|
|
606
|
+
readonly argKind: 'custom';
|
|
527
607
|
}>;
|
|
528
608
|
}
|
|
529
609
|
/**
|