config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 7 Imported by: 0 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryConfig

type BinaryConfig struct {
	Name        string `mapstructure:"name"`
	InstallPath string `mapstructure:"install_path"`
}

BinaryConfig defines a binary to include in bottles. A bare string in YAML is accepted as shorthand for {name: ...}.

type BottleConfig

type BottleConfig struct {
	// Cellar setting for bottles
	Cellar string `mapstructure:"cellar"`

	// Platforms to generate bottles for (empty = auto-discover all)
	Platforms []string `mapstructure:"platforms"`

	// Platforms to exclude from generation
	ExcludePlatforms []string `mapstructure:"exclude_platforms"`

	// Rebuild number (0 for initial release)
	Rebuild int `mapstructure:"rebuild"`

	// Force refresh platform cache
	RefreshPlatforms bool `mapstructure:"refresh_platforms"`
}

BottleConfig defines bottle generation settings

type BuildConfig

type BuildConfig struct {
	// Packages to build (e.g., ["./cmd/myapp"])
	Packages []string `mapstructure:"packages"`

	// Ldflags template (supports {{.Version}}, {{.Commit}}, {{.Date}}, {{.Tag}})
	Ldflags string `mapstructure:"ldflags"`

	// Extra environment variables for go build, as KEY=value strings.
	// (A YAML map would lose case: viper lowercases map keys.)
	Env []string `mapstructure:"env"`

	// Enable CGO (default: false for portable static binaries)
	CGOEnabled bool `mapstructure:"cgo_enabled"`

	// Use -trimpath for reproducible builds (default: true)
	Trimpath bool `mapstructure:"trimpath"`

	// Extra go build flags
	Flags []string `mapstructure:"flags"`

	// Path to go.mod directory (default: ".")
	ModDir string `mapstructure:"mod_dir"`

	// Number of parallel builds (default: GOMAXPROCS)
	Parallel int `mapstructure:"parallel"`
}

BuildConfig defines Go build configuration for ko-like mode

type Config

type Config struct {
	// Formula content (gobottle owns the generated formula outright)
	Formula FormulaConfig `mapstructure:"formula"`

	// Version being bottled (no "v" prefix; normalized in SetDefaults)
	Version string `mapstructure:"version"`

	// Source configuration
	Source SourceConfig `mapstructure:"source"`

	// Bottle configuration
	Bottle BottleConfig `mapstructure:"bottle"`

	// Registry configuration
	Registry RegistryConfig `mapstructure:"registry"`

	// Tap configuration
	Tap TapConfig `mapstructure:"tap"`

	// Binary configuration (multi-binary support)
	Binaries []BinaryConfig `mapstructure:"binaries"`
}

Config represents the complete gobottle configuration. Precedence (highest first): CLI flag > GOBOTTLE_* env > config file > git-derived defaults > built-in defaults.

func Load

func Load(v *viper.Viper) (*Config, error)

Load unmarshals the full configuration from the given viper instance. Because command flags and GOBOTTLE_* env vars are bound into viper, this single call realizes the whole precedence chain: flag > env > config file > flag default.

func (*Config) ApplyGitDefaults

func (c *Config) ApplyGitDefaults()

ApplyGitDefaults attempts to infer configuration values from git context. Uses go-git library instead of exec'ing git binary.

func (*Config) BinaryNames

func (c *Config) BinaryNames() []string

BinaryNames returns just the names of all configured binaries

func (*Config) GitURL

func (c *Config) GitURL() string

GitURL returns the git clone URL for the source repository (for head stanzas).

func (*Config) RootURL

func (c *Config) RootURL() string

RootURL returns the bottle block root_url. Brew appends "/<formula>" to this when constructing manifest and blob URLs, so the formula name must NOT be part of it.

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets default values for the configuration

func (*Config) SourceURL

func (c *Config) SourceURL() string

SourceURL returns the source tarball URL for the formula. Returns explicit URL if set, otherwise derives from GitHub owner/repo/version. Returns empty string when derivation is not possible.

func (*Config) TapGitHubURL

func (c *Config) TapGitHubURL() string

TapGitHubURL returns the GitHub URL for the tap repository

func (*Config) Validate

func (c *Config) Validate() error

Validate performs comprehensive config validation

func (*Config) ValidateFor

func (c *Config) ValidateFor(needToken bool) error

ValidateFor validates the config for a pipeline stage. needToken=false skips the registry-token requirement (local build stage).

type FormulaConfig

type FormulaConfig struct {
	// Name of the formula (default: repo name)
	Name string `mapstructure:"name"`

	// Description for the desc stanza (brew audit requires one; warned if empty)
	Description string `mapstructure:"description"`

	// Homepage URL (default: https://github.com/<owner>/<repo>)
	Homepage string `mapstructure:"homepage"`

	// License as an SPDX identifier; omitted from the formula if empty
	License string `mapstructure:"license"`

	// Head emits a `head "<repo>.git", branch: "<branch>"` stanza
	Head bool `mapstructure:"head"`

	// HeadBranch overrides the head branch (default: "main")
	HeadBranch string `mapstructure:"head_branch"`

	// Dependencies become depends_on lines
	Dependencies []string `mapstructure:"dependencies"`

	// Conflicts become conflicts_with lines
	Conflicts []string `mapstructure:"conflicts"`

	// Caveats is emitted verbatim in a caveats heredoc
	Caveats string `mapstructure:"caveats"`

	// Install customizes the install block beyond bin.install
	Install InstallConfig `mapstructure:"install"`

	// Test customizes the test block
	Test TestConfig `mapstructure:"test"`

	// Service is a verbatim `service do` block body
	Service string `mapstructure:"service"`

	// Template is a path to a Go template overriding the built-in formula
	// template; it receives the full formula model.
	Template string `mapstructure:"template"`
}

FormulaConfig drives formula generation: every overrideable aspect of the rendered formula lives here. A bare string in YAML ("formula: mytool") is accepted as shorthand for {name: mytool}.

type InstallConfig

type InstallConfig struct {
	// Completions emits generate_completions_from_executable for each binary
	Completions bool `mapstructure:"completions"`

	// CompletionsCommand is the subcommand generating completion scripts,
	// invoked as `<binary> <command...> <shell>` (default: ["completion"],
	// the cobra convention)
	CompletionsCommand []string `mapstructure:"completions_command"`

	// Extra lines are appended verbatim to the install block
	Extra []string `mapstructure:"extra"`
}

InstallConfig customizes the generated install block.

type MultiError

type MultiError struct {
	Errors []error
}

MultiError aggregates multiple errors

func (*MultiError) Error

func (e *MultiError) Error() string

type RegistryConfig

type RegistryConfig struct {
	// GHCR configuration
	Host  string `mapstructure:"host"`
	Owner string `mapstructure:"owner"`

	// RootPath is the image path between host and formula name
	// (default: "<owner>/<tap repo minus homebrew- prefix>", mirroring
	// homebrew-core's ghcr.io/homebrew/core/<formula> layout). The formula's
	// root_url becomes "https://<host>/v2/<root_path>"; brew appends the
	// formula name itself. Env: GOBOTTLE_REPO or GOBOTTLE_REGISTRY_ROOT_PATH.
	RootPath string `mapstructure:"root_path"`

	// Authentication token
	Token string `mapstructure:"token"`
}

RegistryConfig defines OCI registry settings

type SourceConfig

type SourceConfig struct {
	// Type: "github", "local", or "go"
	Type string `mapstructure:"type"`

	// GitHub source options
	Owner string `mapstructure:"owner"`
	Repo  string `mapstructure:"repo"`
	Tag   string `mapstructure:"tag"`

	// Local source options
	DistPath string `mapstructure:"dist_path"`

	// Go source options (ko-like mode)
	Build BuildConfig `mapstructure:"build"`

	// Source tarball options (for formula generation)
	URL    string `mapstructure:"url"`    // Source tarball URL (auto-derived if empty)
	SHA256 string `mapstructure:"sha256"` // Source tarball SHA256 (computed if empty)
}

SourceConfig defines where to fetch artifacts from

type TapConfig

type TapConfig struct {
	// Tap repository
	Owner  string `mapstructure:"owner"`
	Repo   string `mapstructure:"repo"`
	Branch string `mapstructure:"branch"`

	// Formula path within tap
	FormulaPath string `mapstructure:"formula_path"`

	// Commit message template
	CommitMessage string `mapstructure:"commit_message"`

	// Token for tap repository (defaults to registry token)
	Token string `mapstructure:"token"`
}

TapConfig defines Homebrew tap repository settings

type TestConfig

type TestConfig struct {
	// Command arguments for `system bin/"<binary>", ...` (default: ["--version"])
	Command []string `mapstructure:"command"`

	// Raw replaces the whole test body verbatim
	Raw string `mapstructure:"raw"`
}

TestConfig customizes the generated test block.

type ValidationError

type ValidationError struct {
	Field   string
	Value   any
	Message string
}

ValidationError represents a configuration validation error

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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