Crust logoCrust

validateParsed()

Validate a parse result against required-value constraints.

Validates a previously-parsed result against its command's required-value constraints. Separated from parseArgs() so that middleware (e.g. --help) can inspect the parse result before validation errors are surfaced.

Signature

function validateParsed(
  command: CommandNode,
  parsed: ParseResult,
): void;

Parameters

ParameterTypeDescription
commandCommandNodeThe command node whose definitions drive validation
parsedParseResultThe parse result from parseArgs()

Returns

void — throws on validation failure.

Throws

  • CrustError("VALIDATION") — Missing required argument or flag

When It's Called

In the standard .execute() pipeline, validateParsed is called after middleware has run. This means plugins like helpPlugin can check flags.help and short-circuit before required-value errors are thrown.

parseArgs()  ->  middleware (e.g. --help)  ->  validateParsed()  ->  preRun -> run -> postRun

Example

import { parseArgs, validateParsed } from "@crustjs/core";

// Parse without validation
const parsed = parseArgs(cmd._node, ["--help"]);

// Middleware can inspect parsed.flags.help here...

// Then validate when ready
validateParsed(cmd._node, parsed);
// Throws CrustError("VALIDATION") if required args/flags are missing

On this page