conditions

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package conditions decides which catalog items may be installed on this machine. Each item's installable_condition is an expr expression (github.com/expr-lang/expr) evaluated against facts that pkg/facts gathers. See site/src/content/docs/guides/conditions.md. It has no platform code, so makecatalogs can check expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(catalogs map[int]map[string]catalog.Item, facts Facts)

Apply evaluates every item's installable_condition against facts and sets NotInstallable on the items it rejects, so the lookups that choose an item to install skip them. Unknown rejects an item like false: the item is not installable here until the machine has the facts it names.

func Check

func Check(condition string) error

Check reports a syntax error in condition without facts, for tools that build catalogs. A condition that passes can still fail on a machine, for example by naming a fact the machine does not have.

func Inputs

func Inputs(condition string) ([]string, error)

Inputs returns, sorted, the facts condition reads, for a template render. A syntax error is an error, and so is a call to a time-dependent builtin such as now(), since the result would then depend on the clock rather than the facts. An empty condition reads nothing: Evaluate holds it True.

Types

type Facts

type Facts map[string]any

Facts maps a fact name to its value: a string, number, bool, or a list of them for the built-in facts; whatever JSON value a script printed for admin facts.

func SampleFacts

func SampleFacts(goos string) Facts

SampleFacts returns an example value for every built-in fact SofCat collects on goos (darwin, windows or linux): the conditions guide's examples (site/src/content/docs/guides/conditions.md, "Built-in facts"). makecatalogs renders templates against them, since it has no machine. The per-OS tests in pkg/facts assert every built-in they collect is here, so the two cannot drift.

type Result

type Result int

Result is a condition's outcome. Unknown means the condition names a fact this machine does not have, so it can be neither honoured nor refused.

const (
	False Result = iota
	True
	Unknown
)

func Evaluate

func Evaluate(condition string, facts Facts) (_ Result, missing []string, _ error)

Evaluate decides condition against facts. An empty condition is True. A condition that names an identifier absent from facts is Unknown, and missing lists those names. A syntax error, a runtime error, or a non-boolean result is False with the error, so a typo hides an item rather than installing it everywhere.

func (Result) String

func (r Result) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL