Documentation
¶
Overview ¶
Package segment holds writ's segments, the built-in ones detection supplies (OS, DISTRO, ARCH) and the extras declared in configuration, and selects a layer's directories with them through the one selector API (pkg/selector, #944).
Index ¶
Constants ¶
const EnvVarPrefix = "WRIT_SEGMENT_"
EnvVarPrefix is the prefix of the environment variables that set a segment's value: WRIT_SEGMENT_ROLE=server.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MatchResult ¶
type MatchResult struct {
// Path is the directory's full path.
Path string
// Project is the project it belongs to: noblefactor.
Project string
// Rank is its place in the order of application.
Rank selector.Rank
}
MatchResult is a directory a selection includes.
func MatchDirectories ¶
func MatchDirectories(sourceRoot string, projects []string, segs Segments) ([]MatchResult, []*selector.GrammarError, error)
MatchDirectories selects a layer's directories for the given projects: the ones this machine includes, in the order to apply them, and every directory name that breaks the selector grammar.
Every directory in the layer is judged, not only the requested projects', because a layer with a malformed name is malformed for every deploy. Hidden directories are not projects and are skipped.
Parameters:
- `sourceRoot`: the layer's Home or System tree.
- `projects`: the projects, in the order they're applied.
- `segs`: this machine's segments.
Returns:
- `[]MatchResult`: the directories included, in the order to apply them; the last applied wins.
- `[]*selector.GrammarError`: every directory name that breaks the grammar.
- `error`: non-nil when the tree cannot be read.
type Refusal ¶
type Refusal struct {
// Entries are the names, each with the tree it was found in.
Entries []RefusalEntry
}
Refusal is every directory name that breaks the selector grammar, in every layer a run reads. writ refuses the run with it before anything changes (ruled 2026-09-30).
type RefusalEntry ¶
type RefusalEntry struct {
// Root is the tree the name was found in.
Root string
// Err is the name and the rule it breaks.
Err *selector.GrammarError
}
RefusalEntry is one directory name that breaks the grammar.
type Segment ¶
type Segment struct {
// Name is the segment's name: OS, DISTRO, ARCH, ROLE.
Name string
// Value is this machine's value: Linux, Ubuntu, arm64, desktop. Empty when unset.
Value string
// Values are an extra's declared values; nil for a built-in.
Values []string
// Lineage is DISTRO's ancestors, most general first: Debian, for Ubuntu. Nil for every other segment.
Lineage []string
}
Segment is one segment: a built-in, or an extra declared in configuration.
type Segments ¶
type Segments []Segment
Segments is this machine's segments: OS, DISTRO and ARCH, then the declared extras in configured order.
func DetectSegments ¶
func DetectSegments() Segments
DetectSegments returns this machine's built-in segments: OS, DISTRO with its lineage, and ARCH.
Returns:
- `Segments`: the built-ins, from selector.Detect. DISTRO is empty off Linux and on a Linux host whose os-release names no distribution.
func Resolve ¶
Resolve returns this machine's segments: the built-ins detection supplies, then the extras configuration declares, each value taken from the command line, else the environment, else configuration.
An extra must be declared, and its value must be one of its declared values: a `--segment` or `WRIT_SEGMENT_` variable naming anything else is refused, because a misspelling would otherwise match nothing and say nothing (ruled 2026-09-30). The built-ins take a value without a declaration.
Parameters:
- `declared`: the extras declared in configuration, in configured order, each with its configured value.
- `flags`: the `--segment NAME=value` flags, in command-line order.
Returns:
- `Segments`: the built-ins, then the extras.
- `error`: the declaration's problems (selector.ValidateSegments), or a variable or flag the declaration refuses.
func (Segments) Extras ¶
Extras returns the declared extras, in configured order, as the selector takes them.
Returns:
- `[]selector.Segment`: the extras.
func (Segments) Get ¶
Get returns a segment's value.
Parameters:
- `name`: the segment's name.
Returns:
- `string`: its value; empty when unset or not a segment.
func (Segments) Host ¶
Host returns the machine the built-in segments describe, overrides included.
Returns:
- `selector.Host`: the machine: its chain is Unix when the OS is a Unix, the OS, then DISTRO's lineage and DISTRO.
func (Segments) Selector ¶
Selector returns the selector for these segments and a list of projects.
Parameters:
- `projects`: the projects, in the order they're applied.
Returns:
- `selector.Selector`: the selector.
func (Segments) Set ¶
Set returns the segments with one segment's value replaced, or with the segment appended when there is none by that name. A replaced DISTRO keeps its lineage: an override names the distribution, not its ancestors.
Parameters:
- `name`: the segment's name.
- `value`: its new value.
Returns:
- `Segments`: a copy with the value set.