@0xdolan/deq-cli
The deq command-line tool for Node.js (ADR 0011).
The executable is deq; main runs it in-process and returns the exit code.
Source: packages/cli. Install with npm install @0xdolan/deq-cli.
Functions
checkSpec
function checkSpec(x: unknown): ShapeDataCheck the structure of a parsed spec file and return it as shape data.
joinPath
function joinPath(dir: string, ...names: string[]): stringdir + separator + name, without normalising what the user typed.
main
function main(argv: readonly string[], io: Io, data?: CliData): Promise<number>Run deq with argv (no program name). Returns the exit code.
paramValue
function paramValue(raw: string): ParamValue--param values: true/false are booleans, decimal numbers are numbers.
parseArgs
function parseArgs(data: CliData, argv: readonly string[]): ParsedParse argv (without the program name) against the shared CLI data.
shapeInfo
function shapeInfo(s: ShapeData): Omit<ShapeData, 'primitives'>The metadata of a shape, without its geometry.
validateSpec
function validateSpec(json: unknown): { id: string; variants: number; }Validate parsed spec JSON. Returns a summary line; throws DeqError (INVALID_SHAPE for
structural problems, or the renderer’s code) naming the first problem.
variants
function variants(shape: ShapeData): Record<string, ParamValue>[]The parameter overrides validate renders: the defaults, then each other value.
Classes
IoError
class IoErrorA file could not be read or written: exit code 3.
UsageError
class UsageErrorA command-line mistake: exit code 2. command names the help to point to.
command: string | undefined
Constants
CLI
const CLI: CliDataThe CLI interface from spec/cli.json: commands, flags, messages and exit codes.
MAX_SPEC_BYTES
const MAX_SPEC_BYTES: numberLargest spec file validate reads.
packageName
const packageName: '@0xdolan/deq-cli'The npm package name.
Interfaces
Arg
interface Argname: stringvariadic?: booleanoptional?: booleanchoices?: readonly string[]complete?: stringhelp: string
CliData
interface CliDataEverything a CLI needs besides the renderers.
name: stringversion: stringformats: { readonly all: readonly string[]; readonly ports: readonly string[]; }globalFlags: readonly Flag[]exitCodes: readonly { readonly code: number; readonly meaning: string; }[]commands: readonly Command[]help: Readonly<Record<string, string>>: Help per command; the key “” is the top-level help.completions: Readonly<Record<string, string>>
Command
interface Commandname: stringsummary: stringargs: readonly Arg[]flags: readonly Flag[]
Flag
interface FlagA command-line flag with its choices resolved.
name: stringshort?: stringtype: FlagTypevalue?: stringchoices?: readonly string[]maxItems?: number: Most items alistorintlistflag takes.default?: stringcomplete?: stringoption?: stringhelp: string
Io
interface IoWhere main reads and writes.
cwd: string: Directory relative paths resolve against.stdout: (data: string | Uint8Array<ArrayBufferLike>) => voidstderr: (text: string) => void
Types
FlagType
type FlagType = "bool" | "string" | "number" | "int" | "choice" | "list" | "intlist" | "pair"The shared CLI data built from spec/cli.json (see scripts/generate.ts).
FlagValue
type FlagValue = boolean | number | string | readonly string[] | readonly number[] | readonly [string, string][]A parsed flag value. Pairs keep their order; lists keep the given order.
Parsed
type Parsed = | { readonly kind: "help"; readonly text: string } | { readonly kind: "version"; readonly text: string } | { readonly kind: "run"; readonly command: Command; readonly args: readonly string[]; readonly flags: ReadonlyMap<string, FlagValue>; }The result of parseArgs: help or version text to print, or a command to run.
A new version of this site is available.