Skip to content

@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): ShapeData

Check the structure of a parsed spec file and return it as shape data.

joinPath

function joinPath(dir: string, ...names: string[]): string

dir + 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[]): Parsed

Parse 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 IoError

A file could not be read or written: exit code 3.

UsageError

class UsageError

A command-line mistake: exit code 2. command names the help to point to.

  • command: string | undefined

Constants

CLI

const CLI: CliData

The CLI interface from spec/cli.json: commands, flags, messages and exit codes.

MAX_SPEC_BYTES

const MAX_SPEC_BYTES: number

Largest spec file validate reads.

packageName

const packageName: '@0xdolan/deq-cli'

The npm package name.

Interfaces

Arg

interface Arg
  • name: string
  • variadic?: boolean
  • optional?: boolean
  • choices?: readonly string[]
  • complete?: string
  • help: string

CliData

interface CliData

Everything a CLI needs besides the renderers.

  • name: string
  • version: string
  • formats: { 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 Command
  • name: string
  • summary: string
  • args: readonly Arg[]
  • flags: readonly Flag[]

Flag

interface Flag

A command-line flag with its choices resolved.

  • name: string
  • short?: string
  • type: FlagType
  • value?: string
  • choices?: readonly string[]
  • maxItems?: number: Most items a list or intlist flag takes.
  • default?: string
  • complete?: string
  • option?: string
  • help: string

Io

interface Io

Where main reads and writes.

  • cwd: string: Directory relative paths resolve against.
  • stdout: (data: string | Uint8Array<ArrayBufferLike>) => void
  • stderr: (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.