GitHub
Skip to content

Output

What a command tells createOut, and how createOut renders it once for the reader.

A command doesn't print. It tells out what it found, and out.end() renders the whole run once, in the format the reader gets. Only createOut writes to the streams.

const out = createOut<{ files: number }>({
  tool: "acme",
  command: "check",
  version: "1.2.0",
  argv: process.argv.slice(2),
  summary: (result) => (result.files === undefined ? undefined : `in ${result.files} files`),
});
ts

tool names the ACME_FORMAT variable and the schema, acme.check/v1 here. argv carries the reader flags. version goes in jsonl's first record. summary adds words after the counts on the verdict line.

maxRows sets how many rows a terminal shows before it hides the rest, 50 by default. io and detection replace the process and the detection, for tests.

out.error({ code: "ACME001", message: "Route handler reads process.env at module scope", file: "src/app.ts", line: 14 });
out.warn("Alias shadows a workspace package");
out.diagnostic({ severity: "info", message: "Cache is cold" });
ts

A diagnostic takes code, message, why, fix, docs, a location (file, line, column, endLine, endColumn) and data. The counts and the status come from them: any error makes the run failed.

out.set({ files: 212 });
ts

set merges fields into the one result. JSON carries it as result, jsonl as the data of its last record.

out.next("acme explain <code>", "explains one code");
ts

Each next is a command the reader can run after this one, with the reason. A confirm that falls back to its default adds one too, such as acme check --fix.

out.log("Applied 2 fixes.");
out.debug("cache hit"); // only with --verbose, on stderr
out.write(markdown);
ts

log is a line in the run. write is an answer the tool rendered itself, such as an explain page. JSON and jsonl carry it as answer.

out.progress(label) shows progress to a person and does nothing for anyone else. out.confirm and out.ask ask a person, or take the answer from a flag, --input or the environment.

return out.end();
ts

end renders the run and returns the exit code: 0 when ok, 1 when failed, 2 when the caller has to change the command. end({ status, summary }) overrides the status or the summary. out.fail(error) renders a failure instead.

out.profile is what readerly decided: format, color, interactive, budget, verbosity, detection, and why, one line per decision.

out.write(out.profile.format === "text" ? await renderAnsi(page, { colors: out.profile.color }) : page);
ts