config

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultGenerationKeep = 10

DefaultGenerationKeep is the number of generations preserved when config.toml has no [generation] section. Sized to cover a typical week of installs while keeping inode usage bounded: at ~28K inodes per gen, 10 gens ≈ 280K inodes total, two orders of magnitude under typical ext4 default budgets.

View Source
const DefaultParallelism = 8

DefaultParallelism is the fallback download parallelism when nothing is configured via GALE_JOBS or sync parallelism.

Variables

View Source
var ErrGaleConfigNotFound = errors.New(
	"gale.toml not found",
)

ErrGaleConfigNotFound is returned when gale.toml cannot be found in the directory tree.

View Source
var ErrPackageNotFound = errors.New("package not found")

ErrPackageNotFound is returned when a package to remove does not exist in the config.

View Source
var ErrRepoNotFound = errors.New("repo not found")

ErrRepoNotFound is returned when a repo to remove does not exist in the config.

Functions

func AddPackage

func AddPackage(path, host, name, version string) error

AddPackage adds or updates a package in the gale.toml at path. When host is empty, the package is written to the shared [packages] section. When non-empty, it is written under [hosts.<host>.packages]. If the file does not exist, it is bootstrapped.

func AddRepo added in v0.9.0

func AddRepo(path string, repo Repo) error

AddRepo adds a repository to the config.toml at path. Creates the file if it does not exist.

func CurrentHost added in v0.16.0

func CurrentHost() string

CurrentHost returns the active host identifier. Reads $GALE_HOST first; falls back to os.Hostname(). Returns "" if both fail.

func FindGaleConfig

func FindGaleConfig(dir string) (string, error)

FindGaleConfig walks up from dir to find gale.toml. Returns the path to the found file.

func FindToolVersions added in v0.4.0

func FindToolVersions(dir string) string

FindToolVersions walks up from dir looking for a .tool-versions file. Returns the path if found, empty string if not.

func HostKeyMatches added in v0.16.3

func HostKeyMatches(sectionKey, host string) bool

HostKeyMatches reports whether sectionKey applies to the given host. The key is a comma-separated list of glob patterns; any matching pattern returns true.

func HostSectionExists added in v0.17.0

func HostSectionExists(path, host string) bool

HostSectionExists reports whether the gale.toml at path already contains a [hosts.<key>] section that applies to host. A key applies when it equals host literally (covers comma-list keys, which HostKeyMatches splits and never compares whole) or when HostKeyMatches in either direction: an exact key, a glob key covering host, or a glob host value covering an exact key all count. Legacy unquoted dotted headers ([hosts.travis-mb.local.packages], pre-#59) parse as nested tables and never reach the typed Hosts map, but the section exists on disk and the mutators normalize and reuse it, so they count too. Errors (unreadable or unparseable file) report true so callers stay quiet and let the subsequent write surface the real problem.

func ParseToolVersions added in v0.4.0

func ParseToolVersions(data string) (map[string]string, error)

ParseToolVersions parses a .tool-versions file into a package map. Each line is "<name> <version> [version...]". Comments start with #. When multiple versions are listed, only the first is used. Names are mapped to gale recipe names where known (e.g., "golang" → "go").

func PinPackage added in v0.6.0

func PinPackage(path, host, name string) error

PinPackage marks a package as pinned in the gale.toml at path. When host is empty, the pin is recorded in shared [pinned] and the package must exist in shared [packages]. Otherwise the pin is recorded under [hosts.<host>.pinned] and the package must exist in that host's package list. Returns ErrPackageNotFound when the package is not in the targeted section.

TODO(0012-0014): PinPackage uses struct round-trip (WriteGaleConfig) which strips comments and drops unknown sections. Convert to text-based edit when setTOMLBoolKey is added.

func RemovePackage

func RemovePackage(path, host, name string) error

RemovePackage removes a package from the gale.toml at path. When host is empty, removes from shared [packages]; otherwise from [hosts.<host>.packages]. Returns ErrPackageNotFound if the package is not present in the targeted section.

func RemoveRepo added in v0.9.0

func RemoveRepo(path string, name string) error

RemoveRepo removes a repository by name from config.toml.

func ResolveParallelism added in v0.16.4

func ResolveParallelism(cfg *AppConfig) int

ResolveParallelism returns the effective download parallelism. Precedence: GALE_JOBS env var, then sync parallelism, then DefaultParallelism. The result is always >= 1.

func UnpinPackage added in v0.6.0

func UnpinPackage(path, host, name string) error

UnpinPackage removes a pin from the gale.toml at path. When host is empty, removes from shared [pinned]; otherwise from [hosts.<host>.pinned]. Missing pins are a no-op.

TODO(0012-0014): UnpinPackage uses struct round-trip (WriteGaleConfig) which strips comments and drops unknown sections. Convert to text-based edit when setTOMLBoolKey is added.

func UpsertPackage added in v0.16.0

func UpsertPackage(path, host, name, version string) error

UpsertPackage updates a package in gale.toml, preserving its existing location. If the package is present in the current host's section, it is updated there; otherwise it is written to the shared [packages] section. Used by install/update flows that should not move a host-scoped package to the shared section. host may be empty (no preservation; equivalent to AddPackage(path, "", ...)).

func WriteAppConfig added in v0.9.0

func WriteAppConfig(path string, cfg *AppConfig) error

WriteAppConfig writes an AppConfig to the given path atomically.

func WriteGaleConfig

func WriteGaleConfig(path string, cfg *GaleConfig) error

WriteGaleConfig writes a GaleConfig to the given path atomically.

Types

type AIConfig

type AIConfig struct {
	APIKey     string `toml:"api_key"`
	PromptFile string `toml:"prompt_file"`
}

AIConfig holds Anthropic API settings.

type AppConfig

type AppConfig struct {
	Repos      []Repo           `toml:"repos"`
	Build      BuildConfig      `toml:"build"`
	Anthropic  AIConfig         `toml:"anthropic"`
	Registry   RegistryConfig   `toml:"registry"`
	Generation GenerationConfig `toml:"generation"`
	Sync       SyncConfig       `toml:"sync"`
}

AppConfig represents ~/.gale/config.toml (app-level settings).

func ParseAppConfig

func ParseAppConfig(data string) (*AppConfig, error)

ParseAppConfig parses a config.toml string.

type BuildConfig added in v0.7.0

type BuildConfig struct {
	Debug bool `toml:"debug,omitempty"`
}

BuildConfig holds build-related settings.

type GaleConfig

type GaleConfig struct {
	Packages map[string]string     `toml:"packages"`
	Vars     map[string]string     `toml:"vars,omitempty"`
	Pinned   map[string]bool       `toml:"pinned,omitempty"`
	Hosts    map[string]HostConfig `toml:"hosts,omitempty"`
}

GaleConfig represents a gale.toml file (global or project).

func ParseGaleConfig

func ParseGaleConfig(data string) (*GaleConfig, error)

ParseGaleConfig parses a gale.toml string.

func (*GaleConfig) ApplyHost added in v0.16.0

func (c *GaleConfig) ApplyHost(host string)

ApplyHost replaces Packages and Pinned with the effective merged maps for the given host. Mutates the receiver. Callers that need the raw on-disk view (e.g. mutators) must not call this.

func (*GaleConfig) EffectivePackages added in v0.16.0

func (c *GaleConfig) EffectivePackages(host string) map[string]string

EffectivePackages returns the shared [packages] merged with every [hosts.<key>.packages] section whose key matches host. Host section keys may list multiple comma-separated patterns and use glob wildcards (*, ?). Wildcard-bearing sections are applied first; exact-name sections last, so exact entries override globs. Does not mutate the receiver.

func (*GaleConfig) EffectivePinned added in v0.16.0

func (c *GaleConfig) EffectivePinned(host string) map[string]bool

EffectivePinned merges shared [pinned] with every matching [hosts.<key>.pinned] overlay, using the same multi-pattern matching and override order as EffectivePackages. Does not mutate the receiver.

type GenerationConfig added in v0.16.3

type GenerationConfig struct {
	Keep int `toml:"keep,omitempty"`
}

GenerationConfig holds gen-retention settings. Keep is the number of recent generations (including the current one) preserved after each rebuild's auto-gc pass. Default 10 when unset or non-positive; set to a negative value to disable auto-gc entirely.

func (GenerationConfig) EffectiveGenerationKeep added in v0.16.3

func (g GenerationConfig) EffectiveGenerationKeep() int

EffectiveGenerationKeep returns the configured Keep value when positive, otherwise DefaultGenerationKeep. A negative value (the "disabled" sentinel) is returned as-is so the caller can short-circuit auto-gc.

type HostConfig added in v0.16.0

type HostConfig struct {
	Packages map[string]string `toml:"packages,omitempty"`
	Pinned   map[string]bool   `toml:"pinned,omitempty"`
}

HostConfig represents a per-host packages/pinned overlay stored under [hosts.<name>] in gale.toml.

type RegistryConfig

type RegistryConfig struct {
	URL string `toml:"url"`
}

RegistryConfig holds registry settings.

type Repo

type Repo struct {
	Name     string `toml:"name"`
	URL      string `toml:"url"`
	Priority int    `toml:"priority"`
}

Repo represents a recipe repository entry in config.toml.

type SyncConfig added in v0.16.4

type SyncConfig struct {
	Parallelism int `toml:"parallelism,omitempty"`
}

SyncConfig controls sync/download behavior. Parallelism is the number of concurrent downloads; default DefaultParallelism when unset or non-positive.

Jump to

Keyboard shortcuts

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