bootstrap

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bootstrap provides configuration schema for repository setup.

The bootstrap configuration allows repository owners to specify which packages should be installed, installation profiles, platform-specific packages, and conflict resolution policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPackageNames

func GetPackageNames(cfg Config) []string

GetPackageNames extracts package names from configuration.

func GetProfile

func GetProfile(cfg Config, profileName string) ([]string, error)

GetProfile retrieves packages for a named profile.

Returns an error if the profile does not exist.

Types

type Config

type Config struct {
	// Version specifies the bootstrap config schema version.
	Version string `yaml:"version"`

	// Packages lists all available packages in the repository.
	Packages []PackageSpec `yaml:"packages"`

	// Profiles defines named sets of packages for different use cases.
	Profiles map[string]Profile `yaml:"profiles,omitempty"`

	// Defaults specifies default settings for installation.
	Defaults Defaults `yaml:"defaults,omitempty"`
}

Config represents the bootstrap configuration for a dotfiles repository.

func Load

func Load(ctx context.Context, fs FS, path string) (Config, error)

Load reads and parses a bootstrap configuration file.

Returns an error if:

  • File cannot be read
  • YAML syntax is invalid
  • Configuration validation fails

The configuration is automatically validated after loading.

func (Config) Validate

func (c Config) Validate() error

Validate checks the configuration for errors.

Returns an error if:

  • Version is missing or empty
  • No packages are defined
  • Package names are empty or duplicated
  • Invalid platform names are used
  • Invalid conflict policies are specified
  • Profiles reference non-existent packages
  • Default profile does not exist

type Defaults

type Defaults struct {
	// ConflictPolicy is the default conflict resolution strategy.
	// Valid values: fail, backup, overwrite, skip
	ConflictPolicy string `yaml:"on_conflict"`

	// Profile is the default profile to use if none specified.
	Profile string `yaml:"profile"`
}

Defaults specifies default configuration values.

type FS

type FS interface {
	ReadFile(ctx context.Context, path string) ([]byte, error)
}

FS defines filesystem operations required for loading bootstrap config.

type GenerateOptions

type GenerateOptions struct {
	// FromManifest only includes packages present in manifest
	FromManifest bool

	// ConflictPolicy sets default conflict resolution policy
	ConflictPolicy string

	// IncludeComments adds helpful comments to generated config
	IncludeComments bool
}

GenerateOptions configures bootstrap generation behavior.

type Generator

type Generator struct{}

Generator creates bootstrap configurations from package information.

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new bootstrap configuration generator.

func (*Generator) Generate

func (g *Generator) Generate(packages []string, installed []string, opts GenerateOptions) (Config, error)

Generate creates a bootstrap configuration from package information.

Parameters:

  • packages: All discovered package names
  • installed: Package names that are currently installed
  • opts: Generation options

Returns a validated bootstrap configuration or an error.

func (*Generator) MarshalYAML

func (g *Generator) MarshalYAML(cfg Config) ([]byte, error)

MarshalYAML converts configuration to YAML bytes.

The output is formatted for human readability with proper indentation and ordering of fields.

func (*Generator) MarshalYAMLWithComments

func (g *Generator) MarshalYAMLWithComments(cfg Config, installed []string) ([]byte, error)

MarshalYAMLWithComments converts configuration to YAML with helpful comments.

type PackageSpec

type PackageSpec struct {
	// Name is the package directory name.
	Name string `yaml:"name"`

	// Required indicates if this package must be installed.
	Required bool `yaml:"required"`

	// Platform restricts installation to specific operating systems.
	// Valid values: linux, darwin, windows, freebsd
	Platform []string `yaml:"platform,omitempty"`

	// ConflictPolicy specifies how to handle conflicts for this package.
	// Valid values: fail, backup, overwrite, skip
	ConflictPolicy string `yaml:"on_conflict,omitempty"`
}

PackageSpec defines a package and its installation requirements.

func FilterPackagesByPlatform

func FilterPackagesByPlatform(packages []PackageSpec, platform string) []PackageSpec

FilterPackagesByPlatform returns packages compatible with the specified platform.

Packages with no platform restrictions are included for all platforms. Packages with platform restrictions are included only if the platform matches.

type Profile

type Profile struct {
	// Description provides human-readable explanation of the profile.
	Description string `yaml:"description"`

	// Packages lists the package names included in this profile.
	Packages []string `yaml:"packages"`
}

Profile represents a named set of packages.

Jump to

Keyboard shortcuts

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