renderGuide(guide: Guide): string
Renders a guidance screen.
Blocks are separated by a blank line and the result carries no trailing
newline, so the caller can hand it straight to console.error or
console.log. The function is pure — the same Guide always
renders the same string — which is what lets the disclosure levels, the
error paths and --help be tested without a process.
The three blocks of an incomplete invocation
The three blocks of an incomplete invocation
import { assertEquals } from "@std/assert"; import { renderGuide } from "./guide.ts"; const text = renderGuide({ next: { word: "<command>", meaning: "what to do with the bytes" }, options: { heading: "COMMANDS", items: [ { name: "decode", summary: "binary on stdin to JSON5 on stdout" }, { name: "encode", summary: "JSON5 on stdin to binary on stdout" }, ], }, try: ["binstruct arp decode < arp.bin > arp.json5"], }); assertEquals(text.split("\n\n"), [ "NEXT <command>\n what to do with the bytes", "COMMANDS\n decode binary on stdin to JSON5 on stdout\n" + " encode JSON5 on stdin to binary on stdout", "TRY\n binstruct arp decode < arp.bin > arp.json5", ]);
Bare names are flowed into columns, and an empty list explains itself
Bare names are flowed into columns, and an empty list explains itself
import { assertEquals, assertStringIncludes } from "@std/assert"; import { renderGuide } from "./guide.ts"; const flowed = renderGuide({ next: { word: "<package>", meaning: "the format package" }, options: { heading: "PACKAGES", items: [{ name: "arp" }, { name: "png" }] }, }); assertStringIncludes(flowed, "\n arp png"); const empty = renderGuide({ header: "package: jsr:@binstruct/pcap", next: { word: "<coder>", meaning: "the coder to run" }, options: { heading: "CODERS", items: [], empty: "discovery is unavailable" }, }); assertEquals(empty.split("\n")[0], "package: jsr:@binstruct/pcap"); assertStringIncludes(empty, "\n discovery is unavailable");
guide: Guide
The screen to render