Documentation
¶
Overview ¶
Package program finds executables by name and joins what different sources report about the same file.
It is mechanism only. It never branches on a program or installer name: the caller says which names to look for, and installers report what they own. A Candidate is an observation, not permission to run the file.
Index ¶
- Constants
- func ExpandRoot(pattern string, env func(string) string) (string, bool)
- type Candidate
- func ForCommands(candidates []Candidate, commands []string) []Candidate
- func Inspect(name, path string) (Candidate, bool)
- func Merge(scanned []Candidate, reports map[string][]Candidate) []Candidate
- func Scan(names []string, pathList string) []Candidate
- func ScanRoots(names, patterns []string, env func(string) string) []Candidate
Constants ¶
const ( SourcePath = "path" SourceInstaller = "installer" )
Source says how a candidate was found.
Variables ¶
This section is empty.
Functions ¶
func ExpandRoot ¶
ExpandRoot turns a directory pattern from a declarative installer into an absolute glob pattern. It understands a leading ~, $NAME, ${NAME} and ${NAME:-default}, where the default may itself start with ~. A value taken from the environment is matched literally, never as a glob. It returns false when a variable without a default is unset or the result is not absolute, so a pattern never depends on the working directory.
Types ¶
type Candidate ¶
type Candidate struct {
Name string `json:"name"`
Path string `json:"path"`
RealPath string `json:"realpath"`
Version string `json:"version,omitempty"`
Source string `json:"source"`
OnPath bool `json:"on_path,omitempty"`
Installers []string `json:"installers,omitempty"`
Attributes map[string]any `json:"attributes,omitempty"`
}
Candidate is one executable file. Path is how the machine reaches it and RealPath is the same file with links resolved; two reports describe one program exactly when their RealPath values are equal.
func ForCommands ¶
ForCommands keeps the candidates whose name is one of commands.
func Inspect ¶
Inspect reports a file named by an installer as a candidate. It returns false for a path that is not an existing regular executable, so an installer cannot claim a file that is not there.
func Merge ¶
Merge joins the PATH scan with what each installer reported. reports maps an installer adapter name to its candidates. A candidate an installer reports is kept only when the file exists; one found on PATH and by an installer is a single result that lists the installer. The result is ordered by name, then RealPath, and installers are in name order, so it is stable between scans.
func Scan ¶
Scan looks for the named programs in the directories of pathList, a PATH style list. It stats files and never runs them. Empty and relative entries are skipped, so the result does not depend on the working directory. Every distinct file is reported, in PATH order, so the first one is what a shell would run; links to one file collapse into the first path that reached it.
func ScanRoots ¶
ScanRoots looks for the named programs in the directories that patterns match. A pattern is expanded with ExpandRoot and matched with filepath.Glob; only directories count, at most maxRootDirectories of them. It stats files and never runs them. Candidates carry no version: the installer's directories do not say more than the layout allows, and the runtime adapter that asked probes the file.