config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config loads diffah's optional YAML configuration file.

Lookup order (first match wins for the file path):

  1. $DIFFAH_CONFIG (must be absolute path)
  2. ~/.diffah/config.yaml
  3. (no file → built-in defaults)

Per-field precedence (most → least specific):

  1. CLI flag (only when explicitly set)
  2. config file value
  3. built-in default

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTo

func ApplyTo(flags *pflag.FlagSet, cfg *Config) error

ApplyTo overwrites the default value of every flag in flags whose name appears in flagNames AND whose value has NOT been explicitly set on the command line (flag.Changed == false). Flags that are present in cfg but missing from flags are silently skipped — this is how commands consume only the subset of fields they care about.

CLI flag override is preserved by the Changed check: a user who passed --workers=2 keeps 2, regardless of what the config file said.

func DefaultPath

func DefaultPath() string

DefaultPath returns the resolved config file path using the lookup chain $DIFFAH_CONFIG > ~/.diffah/config.yaml. Returns an empty string when neither env var nor user home dir is available — Load treats empty path as "no file → use defaults."

func Validate

func Validate(path string) error

Validate parses the config file at path and discards the result. It returns the same errors Load does (in particular *LoadError). A missing file is not an error.

Used by `diffah config validate` and by `diffah doctor`'s config check (Phase 5.1).

Types

type Config

type Config struct {
	Platform      string        `mapstructure:"platform" yaml:"platform" json:"platform"`
	IntraLayer    string        `mapstructure:"intra-layer" yaml:"intra-layer" json:"intra-layer"`
	Authfile      string        `mapstructure:"authfile" yaml:"authfile" json:"authfile"`
	RetryTimes    int           `mapstructure:"retry-times" yaml:"retry-times" json:"retry-times"`
	RetryDelay    time.Duration `mapstructure:"retry-delay" yaml:"retry-delay" json:"retry-delay"`
	ZstdLevel     int           `mapstructure:"zstd-level" yaml:"zstd-level" json:"zstd-level"`
	ZstdWindowLog string        `mapstructure:"zstd-window-log" yaml:"zstd-window-log" json:"zstd-window-log"`
	Workers       int           `mapstructure:"workers" yaml:"workers" json:"workers"`
	Candidates    int           `mapstructure:"candidates" yaml:"candidates" json:"candidates"`
}

Config holds the v1 set of nine flag defaults loadable from ~/.diffah/config.yaml. Per-command applicability is documented in the design spec §5.1; fields irrelevant to a given command (e.g., RetryTimes on `diff`) are silently ignored at ApplyTo time.

All three tag families use the same kebab-case key so `config init` output round-trips through `config validate` (yaml.Marshal uses yaml tags; viper uses mapstructure tags; encoding/json uses json tags).

func Default

func Default() *Config

Default returns the built-in default Config used when no config file is found. These values are the single source of truth for "no flag and no config" behavior; CLI flag defaults installed by individual commands must agree with these.

func Load

func Load(path string) (*Config, error)

Load reads the config file at path and returns the resolved Config. A non-existent path is not an error — Default() is returned. A file that exists but fails to parse, or contains unknown / wrong-typed fields, returns a *LoadError (CategoryUser).

Pass an empty string to skip file lookup entirely (returns defaults).

type LoadError

type LoadError struct {
	Path string
	Err  error
}

LoadError is the sentinel error produced for any malformed config file content (bad YAML, unknown field, type mismatch). It surfaces as CategoryUser through cmd.Execute → exit code 2.

func (*LoadError) Category

func (*LoadError) Category() errs.Category

func (*LoadError) Error

func (e *LoadError) Error() string

func (*LoadError) NextAction

func (*LoadError) NextAction() string

func (*LoadError) Unwrap

func (e *LoadError) Unwrap() error

Jump to

Keyboard shortcuts

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