~/bend-docscommunity

src/ws/root.bend checks

raw source on the hub · import ezx@1.15.0.0/src/ws/root.bend as Root

ws/root: which workspace a command run in a directory belongs to (laws/WorkspaceRootFound.bend). ez reads ez.toml from the directory it runs in; in a workspace that directory may be a member, so a command first finds its root: the nearest directory at or above it, up to the top of the git checkout, whose ledger is a workspace root that makes it a member. With none, the directory is a project of its own, as it always was. The design is docs/rfc/ez-workspaces.md.

Both halves are pure. asks names the directories whose ez.toml the interpreter reads, each with the path from it down to where ez runs, nearest first; root.go decides from what was read, in that order. A path is its segments, relative to the top of the checkout, as git rev-parse --show-prefix prints it (here.of).

2 imports
import Base
import ./workspace.bend as W

Types

type Ask source · line 19 · raw

Data

a directory at or above where ez runs: its path from the top of the checkout, and the path from it down to where ez runs

type Up source · line 23 · raw

Data

one such directory, read: its ez.toml's text, or None when it has none

type Found source · line 29 · raw

Data

where a command run in a directory stands: in a project of its own, in a workspace at root as the member rel below it ([] for the root itself), or nowhere, because a workspace table above it could not be read

Definitions

def here.of source · line 37 · raw

@+prefix:String -> Maybe<&2, List<&2, String>>

where ez runs, from what git rev-parse --show-prefix printed: the segments before the / it ends with, none at the top. Anything else is no answer.

def asks.under source · line 42 · raw

@+hd:String -> @xs:List<&2, Ask> -> List<&2, Ask>

every directory asked about from one segment further down, now one segment further from the top

def asks source · line 51 · raw

@here:List<&2, String> -> List<&2, Ask>

the directories whose ez.toml is read: where ez runs, then each directory above it in turn, ending at the top of the checkout

def claims source · line 61 · raw

@+spec:0x54c6454e798d1d497bdd6d0af3a8ac92/src/ws/workspace.Spec -> @rel:List<&2, String> -> Bool

whether a workspace root makes the directory this far below it a member: the root itself always, and any other when an entry names it and no exclusion does

def root.claim source · line 70 · raw

@hit:Bool -> @+dir:List<&2, String> -> @+rel:List<&2, String> -> @rest:Found -> Found

a workspace root claims the directory, so the search ends there, or does not, and goes on above it

def root.read source · line 79 · raw

@rd:0x54c6454e798d1d497bdd6d0af3a8ac92/src/ws/workspace.Read -> @+dir:List<&2, String> -> @+rel:List<&2, String> -> @rest:Found -> Found

what one directory's ledger says, against what the directories above it decided

def root.at source · line 89 · raw

@text:Maybe<&2, String> -> @+dir:List<&2, String> -> @+rel:List<&2, String> -> @rest:Found -> Found

one directory, with or without a ledger

def root.go source · line 99 · raw

@ups:List<&2, Up> -> Found

the root, from the directories read, nearest first: the first whose ledger is a workspace root that claims where ez runs, a table that could not be read if one comes first, and a project of its own when there is neither