IF Commons GitHub

governance/location

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0002-anyfs-cli-governance FR-005, 0002-anyfs-cli-governance FR-006

Where a word of a command line points (commons anyfs-cli 0002-anyfs-cli-governance FR-005, FR-006): a plain path on this computer, a mount of the configuration (fleet:/machines), or the address of a store (ssh://host/srv/fleet, memory:scratch). The grammar is a pure function of the word and the names of the mounts, so that what a word means never depends on what is on the disk; a word that looks like a mount (name:) and is none is an error that says so, never a file.

import { parseLocation } from "./location.ts";
const mounts = new Set(["fleet"]);
parseLocation("fleet:/machines", mounts); // { kind: "ok", value: { kind: "mount", mount: "fleet", path: "/machines" } }
parseLocation("./notes.txt", mounts); // { kind: "ok", value: { kind: "local", path: "./notes.txt" } }

Source: commons/anyfs-cli/src/governance/location.ts

2 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

MountNametypeno test imports it
type MountName = Brand<string, "anyfs-cli mount name">;

The name of a mount: lower-case words joined by hyphens, two to thirty-two characters, and not the name of a kind of place.

parseMountNamefunction
function parseMountName(text: string): Result<MountName, string>

A mount name from text, or why the text is not one.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Locationtypeno test imports it
type Location =
  | { readonly kind: "local"; readonly path: string }
  | { readonly kind: "mount"; readonly mount: MountName; readonly path: string }
  | { readonly kind: "place"; readonly place: Place; readonly path: string };

Where a word points. The path of a place is the path inside the store, which is rooted at the root of the place.

LocationProblemtypeno test imports it
type LocationProblem = { readonly code: "E-LOCATION" | "E-MOUNT-UNKNOWN"; readonly message: string };

Why a word is not a location.

parseLocationfunction
function parseLocation(text: string, mounts: ReadonlySet<string>): Result<Location, LocationProblem>

Where a word points, given the names of the mounts. A path inside a mount starts with a slash, or is left out for the root of the mount.

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.