Documentation
¶
Overview ¶
Package segment provides segment-based directory matching for writ.
Index ¶
- Constants
- func GroupByProject(results []MatchResult) map[string][]MatchResult
- func OSFamily(os string) string
- func ParseDirName(dirname string) (project string, suffixes []string)
- func ProjectNames(results []MatchResult) []string
- type MatchResult
- type Segment
- type Segments
- func (s Segments) AllValues() []string
- func (s Segments) Get(name string) string
- func (s Segments) LoadFromEnv() Segments
- func (s Segments) Match(dirname string) bool
- func (s Segments) Set(name, value string) Segments
- func (s Segments) SetValues(values map[string]string) (Segments, error)
- func (s Segments) String() string
- func (s Segments) Values() []string
- type UndefinedSegmentError
Constants ¶
const EnvVarPrefix = "WRIT_SEGMENT_"
EnvVarPrefix is the prefix for segment environment variables. Segments are set via WRIT_SEGMENT_<NAME>=<value> (e.g., WRIT_SEGMENT_ROLE=server).
Variables ¶
This section is empty.
Functions ¶
func GroupByProject ¶
func GroupByProject(results []MatchResult) map[string][]MatchResult
GroupByProject groups match results by project name. Within each group, directories are sorted by specificity (most specific first).
func ParseDirName ¶
ParseDirName parses a directory name into project and suffixes. Example: "noblefactor.Darwin.arm64" → "noblefactor", ["Darwin", "arm64"]
func ProjectNames ¶
func ProjectNames(results []MatchResult) []string
ProjectNames returns the unique project names from match results in sorted order.
Types ¶
type MatchResult ¶
type MatchResult struct {
Path string // Full path to directory
Project string // Project name (e.g., "noblefactor")
Suffixes []string // Matched suffixes (e.g., ["Darwin", "arm64"])
}
MatchResult represents a matched directory.
func MatchAllProjects ¶
func MatchAllProjects(sourceRoot string, segs Segments) ([]MatchResult, error)
MatchAllProjects finds all matching directories for all projects in sourceRoot. It returns results sorted by project name, then by specificity (most specific first).
func MatchDirectories ¶
func MatchDirectories(sourceRoot string, projects []string, segs Segments) ([]MatchResult, error)
MatchDirectories finds all matching directories in sourceRoot for the given projects. It returns results sorted by project name, then by specificity (most specific first).
func (MatchResult) Specificity ¶
func (m MatchResult) Specificity() int
Specificity returns the number of matched suffixes. Higher specificity means more specific match.
type Segment ¶
type Segment struct {
Name string // e.g., "OS", "DISTRO", "ROLE"
Value string // e.g., "Darwin", "debian", "desktop"
}
Segment represents a single segment value (e.g., OS="Darwin", ROLE="desktop").
type Segments ¶
type Segments []Segment
Segments is an ordered list of segments for matching. Order matters: OS, DISTRO, ARCH, then custom segments.
func DetectSegments ¶
func DetectSegments() Segments
DetectSegments returns segments for the current platform. Returns OS, DISTRO (Linux only), and ARCH segments.
func DetectSegmentsWithNames ¶
DetectSegmentsWithNames returns segments with custom segment names from config. Custom segment names (like ROLE, SITE) are appended after OS, DISTRO, ARCH. Values are empty until set via CLI --segment flags. Unassigned segments behave like DISTRO on macOS: directories with that suffix won't match.
func (Segments) AllValues ¶
AllValues returns all matchable values including OS family. For OS=Darwin, returns ["Darwin", "Unix"].
func (Segments) LoadFromEnv ¶
LoadFromEnv reads segment values from environment variables. Only loads values for segments already defined in segs. Environment variable format: WRIT_SEGMENT_<NAME>=<value> Returns a new Segments with values populated from environment.
func (Segments) Match ¶
Match checks if a directory name matches the given segments. Returns true if all suffixes match segment values (including OS family).
func (Segments) Set ¶
Set returns a new Segments with the named segment set to value. If the segment doesn't exist, it is appended.
func (Segments) SetValues ¶
SetValues applies CLI --segment values to existing segments. Returns an error if a value references a segment name not defined in segs. Values format: map[name]value (e.g., {"ROLE": "server", "SITE": "aws"})
type UndefinedSegmentError ¶
type UndefinedSegmentError struct {
Name string
}
UndefinedSegmentError indicates a CLI --segment referenced an undefined segment name.
func (*UndefinedSegmentError) Error ¶
func (e *UndefinedSegmentError) Error() string