Documentation
¶
Overview ¶
Package config loads diffah's optional YAML configuration file.
Lookup order (first match wins for the file path):
- $DIFFAH_CONFIG (must be absolute path)
- ~/.diffah/config.yaml
- (no file → built-in defaults)
Per-field precedence (most → least specific):
- CLI flag (only when explicitly set)
- config file value
- built-in default
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTo ¶
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."
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 ¶
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 ¶
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.