program

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 5 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 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

View Source
const (
	SourcePath      = "path"
	SourceInstaller = "installer"
)

Source says how a candidate was found.

Variables

This section is empty.

Functions

func ExpandRoot

func ExpandRoot(pattern string, env func(string) string) (string, bool)

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

func ForCommands(candidates []Candidate, commands []string) []Candidate

ForCommands keeps the candidates whose name is one of commands.

func Inspect

func Inspect(name, path string) (Candidate, bool)

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

func Merge(scanned []Candidate, reports map[string][]Candidate) []Candidate

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

func Scan(names []string, pathList string) []Candidate

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

func ScanRoots(names, patterns []string, env func(string) string) []Candidate

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.

Jump to

Keyboard shortcuts

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