config

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config implements layered YAML configuration for SSU.

Configuration is loaded in priority order (highest wins):

  1. CLI flags (--jobs, --verbose, etc.)
  2. Environment variables (SSU_GIT_PARALLEL_JOBS, etc.)
  3. Project config (.ssu.yaml in project root)
  4. Global config (~/.ssu/config.yaml)
  5. Built-in defaults

The legacy PARALLEL_JOBS env var (without SSU_ prefix) is silently supported but SSU_GIT_PARALLEL_JOBS takes priority when both are set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(projectRoot string) (*Config, *AnnotatedConfig, error)

Load reads configuration from defaults, global config, project config, and environment variables. It returns the merged Config and an AnnotatedConfig tracking which layer set each value.

The projectRoot parameter is the git repository root (or cwd if not in a repo). Missing config files are silently skipped. Malformed config files return an error.

func WithAnnotated

func WithAnnotated(ctx context.Context, ac *AnnotatedConfig) context.Context

WithAnnotated stores an AnnotatedConfig in the context.

func WithConfig

func WithConfig(ctx context.Context, cfg *Config) context.Context

WithConfig stores a Config in the context.

Types

type AnnotatedConfig

type AnnotatedConfig struct {
	// contains filtered or unexported fields
}

AnnotatedConfig tracks which layer set each configuration key. Keys use flat dot-notation (e.g., "git.parallel_jobs").

func AnnotatedFromContext

func AnnotatedFromContext(ctx context.Context) *AnnotatedConfig

AnnotatedFromContext retrieves the AnnotatedConfig from the context. Returns nil if no AnnotatedConfig is stored.

func NewAnnotatedConfig

func NewAnnotatedConfig() *AnnotatedConfig

NewAnnotatedConfig creates an empty AnnotatedConfig.

func (*AnnotatedConfig) Get

func (ac *AnnotatedConfig) Get(key string) AnnotatedValue

Get returns the annotated value for a config key. If the key is not found, it returns an AnnotatedValue with nil Value and SourceDefault.

func (*AnnotatedConfig) Keys

func (ac *AnnotatedConfig) Keys() []string

Keys returns all tracked config keys in no particular order.

func (*AnnotatedConfig) Set

func (ac *AnnotatedConfig) Set(key string, value any, source Source)

Set records a value and its source for a config key.

type AnnotatedValue

type AnnotatedValue struct {
	Value  any
	Source Source
}

AnnotatedValue pairs a configuration value with the source that set it.

type BackupConfig

type BackupConfig struct {
	Enabled    bool `mapstructure:"enabled"`
	MaxBackups int  `mapstructure:"max_backups"`
}

BackupConfig holds backup behavior settings.

type BranchConfig

type BranchConfig struct {
	Priority []string `mapstructure:"priority"`
	Override string   `mapstructure:"override"`
}

BranchConfig holds branch detection settings.

type Config

type Config struct {
	Git      GitConfig    `mapstructure:"git"`
	Branches BranchConfig `mapstructure:"branches"`
	Backup   BackupConfig `mapstructure:"backup"`
	Log      LogConfig    `mapstructure:"log"`
}

Config holds all SSU configuration values.

func Defaults

func Defaults() Config

Defaults returns a Config populated with built-in default values.

func FromContext

func FromContext(ctx context.Context) *Config

FromContext retrieves the Config from the context. Returns nil if no Config is stored.

type GitConfig

type GitConfig struct {
	ParallelJobs int      `mapstructure:"parallel_jobs"`
	Skip         []string `mapstructure:"skip"`
	FailFast     bool     `mapstructure:"fail_fast"`
}

GitConfig holds git operation settings.

type LogConfig

type LogConfig struct {
	MaxSizeMB  int `mapstructure:"max_size_mb"`
	MaxBackups int `mapstructure:"max_backups"`
}

LogConfig holds logging settings.

type Source

type Source string

Source identifies which configuration layer set a value.

const (
	// SourceDefault means the value comes from built-in defaults.
	SourceDefault Source = "default"

	// SourceGlobal means the value was set in ~/.ssu/config.yaml.
	SourceGlobal Source = "global (~/.ssu/config.yaml)"

	// SourceProject means the value was set in .ssu.yaml.
	SourceProject Source = "project (.ssu.yaml)"

	// SourceEnv means the value was set via an SSU_ environment variable.
	SourceEnv Source = "env"

	// SourceFlag means the value was set via a CLI flag.
	SourceFlag Source = "flag"
)

Jump to

Keyboard shortcuts

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