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 ​

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>;

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>;

min ​

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

optional ​

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

required ​

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

stdin ​

ts
stdin(): 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.