FlagFactory
Factory that creates FlagBuilder instances seeded with the correct FlagKind and initial type-level config.
- Import:
@kjanat/dreamcli - Export kind: interface
- Declared in:
src/core/schema/flag.ts - Source link:
src/core/schema/flag.ts:2308
Signatures
interface FlagFactory {}Members
Methods
string
String-valued flag, with optional string constraints.
Constraints are enforced at the parse and resolution boundaries, in fixed order: nonEmpty → minLength → maxLength → pattern. They also compose via chained methods (.nonEmpty(), .minLength(), .maxLength(), .pattern()), which override values set here.
string(constraints?: StringConstraints): FlagBuilder<{ valueType: string; presence: "optional"; optionalFallback: "undefined"; flagKind: "string"; elementEligible: true; }>;number
Number-valued flag, with optional numeric constraints.
Constraints are enforced at the parse and resolution boundaries. The resolved value type stays number — constraints are runtime + schema, not type-level. Bounds are inclusive.
Constraints also compose via chained methods (.int(), .min(), .max(), .finite()), which override values set here.
number(constraints?: NumberConstraints): FlagBuilder<{ valueType: number; presence: "optional"; optionalFallback: "undefined"; flagKind: "number"; elementEligible: true; }>;boolean
Boolean flag. Implicitly defaults to false — the only flag kind where the absence of a value is still meaningful (not undefined).
boolean<O extends { separateValue?: boolean; } | undefined>(options?: O): FlagBuilder<{ valueType: boolean; presence: "defaulted"; optionalFallback: "undefined"; flagKind: "boolean"; elementEligible: true extends NonNullable<O>["separateValue"] ? false : true; }>;enum
Enum flag with literal type inference.
Requires a non-empty readonly tuple so that T[number] produces a union of string literals rather than just string.
enum<T extends readonly [string, ...string[]]>(values: T): FlagBuilder<{ valueType: T[number]; presence: "optional"; optionalFallback: "undefined"; flagKind: "enum"; elementEligible: true; }>;array
Array flag — collects multiple values of the same element type.
array<E extends FlagConfig & { elementEligible: true; }>(element: FlagBuilder<E>, options?: { variadic?: boolean; }): FlagBuilder<{ valueType: E["valueType"][]; presence: "optional"; optionalFallback: "empty-array"; flagKind: "array"; elementEligible: false; }>;custom
Custom flag validated by a Standard Schema v1 validator (zod, valibot, arktype, …). The resolved value from any source is validated after resolution; the flag's value type is the validator's output type.
Sync and async validators are both supported. Validation issues surface as a CONSTRAINT_VIOLATED error naming the flag.
Custom-parsed flag. The parse function receives the raw value and must return a value of type T. The return type is inferred from parseFn.
The input is string from CLI argv and env vars, or any JSON value from config files. Narrow inside the function as needed:
flag.custom((raw: unknown): string[] => {
if (Array.isArray(raw)) return raw.map(String);
if (typeof raw === 'string') return raw.split(',');
throw new Error(`Expected string or array, got ${typeof raw}`);
})Throw an Error (or ParseError) to signal invalid input — it will be wrapped with context and re-thrown as a ParseError.
custom<S extends StandardSchemaV1>(schema: S): FlagBuilder<{ valueType: InferStandardOutput<S>; presence: "optional"; optionalFallback: "undefined"; flagKind: "custom"; elementEligible: true; }>;
custom<T>(parseFn: FlagParseFn<T>): FlagBuilder<{ valueType: T; presence: "optional"; optionalFallback: "undefined"; flagKind: "custom"; elementEligible: true; }>;url
URL-valued flag. Parses into a URL; invalid URLs are rejected with an INVALID_VALUE error naming the flag.
url(options?: UrlFlagOptions): FlagBuilder<{ valueType: URL; presence: "optional"; optionalFallback: "undefined"; flagKind: "custom"; elementEligible: true; }>;path
Path-valued flag. The value stays a string; optional filesystem checks run after resolution through the runtime adapter, so CLI, env, config, prompted, and defaulted values are all validated.
path(options?: PathFlagOptions): FlagBuilder<{ valueType: string; presence: "optional"; optionalFallback: "undefined"; flagKind: "string"; elementEligible: true; }>;date
Date-valued flag. Accepts strict ISO-8601 (2026-07-10, 2026-07-10T14:30:00Z) and parses into a Date. Lenient Date.parse inputs ('0', 'March 5') and calendar-invalid dates (2026-02-31) are rejected.
Returns Date (not Temporal) because the supported runtimes do not all ship Temporal yet; use flag.custom() with Temporal.PlainDate.from where the target runtime has it.
date(options?: DateFlagOptions): FlagBuilder<{ valueType: Date; presence: "optional"; optionalFallback: "undefined"; flagKind: "custom"; elementEligible: true; }>;duration
Duration flag. Accepts '30s', '5m', '1.5h', '250ms', '2d', compounds like '1h30m', or a bare millisecond count, and resolves to milliseconds.
duration(): FlagBuilder<{ valueType: number; presence: "optional"; optionalFallback: "undefined"; flagKind: "custom"; elementEligible: true; }>;bytes
Byte-size flag. Accepts '512mb', '1.5gb', '64kb', '100b' or a bare byte count, and resolves to bytes. Units are binary (1kb = 1024) and case-insensitive.
bytes(): FlagBuilder<{ valueType: number; presence: "optional"; optionalFallback: "undefined"; flagKind: "custom"; elementEligible: true; }>;count
Count flag — resolves to how many times the flag appears. -vvv, -v -v -v, and --verbose --verbose --verbose all yield 3; absent yields 0. An explicit value (--verbose=2, env, config) sets the count directly.
Not promptable.
count(): FlagBuilder<{ valueType: number; presence: "defaulted"; optionalFallback: "undefined"; flagKind: "count"; elementEligible: false; }>;keyValue
Key-value flag — repeated KEY=VALUE occurrences merge into a Record<string, string> (docker/kubectl --env style). The value is split at the first =, so --env A=b=c yields { A: 'b=c' }. Later occurrences of the same key win, which .duplicateKeys() changes. Absent resolves to {}.
Env vars accept comma-delimited pairs (A=1,B=2); config files accept a plain object; .split() sets any of that per source. Not promptable.
An element builder gives each entry value its own codec, constraints, and checks, so flag.keyValue(flag.path()) checks every value on disk.
keyValue<E extends FlagConfig & { elementEligible: true; }>(element?: FlagBuilder<E>): FlagBuilder<{ valueType: Record<string, E["valueType"]>; presence: "optional"; optionalFallback: "empty-object"; flagKind: "keyValue"; elementEligible: false; }>;