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<WithoutArgElementEligibility<ArgBuilder.C>>;

default ​

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

deprecated ​

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

describe ​

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

duplicateKeys ​

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

env ​

ts
env(varName: string): ArgBuilder<WithoutArgElementEligibility<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<WithoutArgElementEligibility<ArgBuilder.C>>;

required ​

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

sensitive ​

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

separator ​

ts
separator(this: ArgBuilder<ArgBuilder.C & { variadic: true; }> | ArgBuilder<ArgBuilder.C & { argKind: "keyValue"; }>, value: string): ArgBuilder<ArgBuilder.C>;

split ​

ts
split(this: ArgBuilder<ArgBuilder.C & { variadic: true; }> | ArgBuilder<ArgBuilder.C & { argKind: "keyValue"; }>, options: SplitOptions): ArgBuilder<ArgBuilder.C>;

standard ​

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

stdin ​

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

unique ​

ts
unique(this: ArgBuilder<ArgBuilder.C & { argKind: ListArgKind; variadic: true; }>, 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.