Skip to main content
Version: v0.0.4

Function: resolveInput()

resolveInput(source, formatOverride, deps, op): Promise<InputResolution>

Resolve and read the input, and resolve its format, for a file-consuming command.

Parameters

source

string | undefined

The positional <file|-> argument (or undefined when it was omitted).

formatOverride

string | undefined

The raw --format value, or undefined to autodetect by content.

deps

RunDeps

Injected input readers (RunDeps).

op

Op

The wrapping operation the caller will run; the resolved format is confirmed to support it (else a value-free CLI_FORMAT_UNSUPPORTED naming the supporting formats).

Returns

Promise<InputResolution>

{ ok: true, input } when the bytes read and the format resolved to a parser supporting op; else { ok: false, result } with a value-free usage/no-input/data-error RunResult.

Throws

Propagates a non-CliError read failure unchanged, so the dispatcher maps it to CLI_INTERNAL (a CliError read failure, e.g. a missing file, is caught and returned).

Example

import { resolveInput } from "@cosyte/cli";

const deps = {
readFile: async () => new TextEncoder().encode('{"resourceType":"Patient"}'),
readStdin: async () => new Uint8Array(),
};
const r = await resolveInput("patient.json", undefined, deps, "parse");
if (r.ok) r.input.format; // => "fhir"