Skip to content

ArgBuilder

Immutable positional argument schema builder.

The type parameter C is a phantom that tracks the value type, presence, and variadic state through the fluent chain. Each modifier returns a new builder — the original is never mutated.

Signatures

ts
class ArgBuilder<C extends ArgConfig> {}

Members

Constructors

constructor

ts
constructor();

Properties

_config

Type brand — exists only in the type system (declare produces no runtime property). Used by InferArg / InferArgs.

ts
_config: ArgBuilder.C;

schema

Runtime schema descriptor.

ts
schema: ArgSchema;

Methods

config

ts
config(path: string): ArgBuilder<ArgBuilder.C>;

default

ts
default<V extends unknown>(value: V): ArgBuilder<WithArgPresence<ArgBuilder.C, "defaulted">>;

deprecated

ts
deprecated(message?: string): ArgBuilder<ArgBuilder.C>;

describe

ts
describe(description: string): ArgBuilder<ArgBuilder.C>;

duplicateKeys

ts
duplicateKeys(this: ArgBuilder<ArgBuilder.C & { argKind: "keyValue"; }>, policy: "error" | "last" | "first"): ArgBuilder<ArgBuilder.C>;

env

ts
env(varName: string): ArgBuilder<ArgBuilder.C>;

finite

ts
finite(this: ArgBuilder<ArgBuilder.C & { argKind: "number"; }>, allow: boolean): ArgBuilder<ArgBuilder.C>;

int

ts
int(this: ArgBuilder<ArgBuilder.C & { argKind: "number"; }>, value: boolean): ArgBuilder<ArgBuilder.C>;

max

ts
max(this: ArgBuilder<ArgBuilder.C & { argKind: "number"; }>, value: number): ArgBuilder<ArgBuilder.C>;

maxLength

ts
maxLength(this: ArgBuilder<ArgBuilder.C & { argKind: "string"; }>, value: number): ArgBuilder<ArgBuilder.C>;

min

ts
min(this: ArgBuilder<ArgBuilder.C & { argKind: "number"; }>, value: number): ArgBuilder<ArgBuilder.C>;

minLength

ts
minLength(this: ArgBuilder<ArgBuilder.C & { argKind: "string"; }>, value: number): ArgBuilder<ArgBuilder.C>;

nonEmpty

ts
nonEmpty(this: ArgBuilder<ArgBuilder.C & { argKind: "string"; }>, value: boolean): ArgBuilder<ArgBuilder.C>;

optional

ts
optional(): ArgBuilder<WithArgPresence<ArgBuilder.C, "optional">>;

pattern

ts
pattern(this: ArgBuilder<ArgBuilder.C & { argKind: "string"; }>, value: RegExp): ArgBuilder<ArgBuilder.C>;

prompt

ts
prompt(config: AllowedArgPromptConfig<ArgBuilder.C>): ArgBuilder<ArgBuilder.C>;

required

ts
required(): ArgBuilder<WithArgPresence<ArgBuilder.C, "required">>;

separator

ts
separator(value: string): ArgBuilder<ArgBuilder.C>;

split

ts
split(options: SplitOptions): ArgBuilder<ArgBuilder.C>;

standard

ts
standard(schema: StandardSchemaV1): ArgBuilder<ArgBuilder.C>;

stdin

ts
stdin(options?: StdinOptions): ArgBuilder<ArgBuilder.C>;

unique

ts
unique(value: boolean): ArgBuilder<ArgBuilder.C>;

variadic

ts
variadic(): ArgBuilder<WithVariadic<ArgBuilder.C>>;

Examples

ts
// Full command with multiple args and modifiers
import { command, arg } from '@kjanat/dreamcli';

command('deploy')
  .arg('target', arg.string()
    .env('DEPLOY_TARGET')
    .describe('Deploy target'))
  .arg('port', arg.number()
    .env('PORT')
    .default(3000)
    .describe('Port number'))
  .arg('files', arg.string()
    .variadic()
    .optional()
    .describe('Extra config files'))
  .action(({ args }) => {
    args.target; // string  (required, from CLI or $DEPLOY_TARGET)
    args.port;   // number  (defaulted, from CLI, $PORT, or 3000)
    args.files;  // string[] (optional variadic)
  });
ts
// Type inference
const target = arg.string();
type T = InferArg<typeof target>; // string

const opt = arg.string().optional();
type O = InferArg<typeof opt>; // string | undefined

const files = arg.string().variadic();
type F = InferArg<typeof files>; // string[]

See Also

Released under the MIT License.