Skip to content

MiddlewareParams

Parameters received by a middleware function at runtime.

Middleware receives erased args, flags, and provenance (since it's defined independently of commands) plus the accumulated context from prior middleware and a next function to continue the chain.

Signatures

ts
interface MiddlewareParams {}

Members

Properties

args

Fully resolved positional arguments (type-erased).

ts
args: Readonly<Record<string, unknown>>;

ctx

Context accumulated from previous middleware in the chain.

ts
ctx: Readonly<Record<string, unknown>>;

flags

Fully resolved flags (type-erased).

ts
flags: Readonly<Record<string, unknown>>;

meta

CLI program metadata (name, bin, version, command).

ts
meta: CommandMeta;

next

Continue to the next middleware or action handler.

Call with context additions that merge into ctx for downstream. Returns when the entire downstream chain completes — enabling wrap-around patterns (timing, try/catch, cleanup).

ts
next: { (additions: Record<string, unknown>): Promise<void>; };

out

Output channel.

ts
out: Out;

sources

Where each resolved value came from, keyed like flags and args.

Erased alongside them, so any key reads as ResolutionProvenance | undefined. A key the bound command never declared, and one an input resolved no value for, both read undefined.

ts
sources: ErasedInputSources;

See Also

Released under the MIT License.