config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config provides layered configuration loading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOverrides

func ApplyOverrides(cfg *Config, o FlagOverrides)

ApplyOverrides applies non-empty flag overrides to cfg. Exported so root.go can re-apply after profile overlay.

func GlobalConfigDir

func GlobalConfigDir() string

GlobalConfigDir returns the global config directory path.

func LoadFromEnv

func LoadFromEnv(cfg *Config)

LoadFromEnv loads configuration from environment variables. Exported so root.go can re-apply after profile overlay.

func NormalizeBaseURL

func NormalizeBaseURL(url string) string

NormalizeBaseURL ensures consistent URL format (no trailing slash).

Types

type Config

type Config struct {
	// API settings
	BaseURL    string `json:"base_url"`
	AccountID  string `json:"account_id"`
	ProjectID  string `json:"project_id"`
	TodolistID string `json:"todolist_id"`

	// Profile settings (named identity+environment bundles)
	Profiles       map[string]*ProfileConfig `json:"profiles,omitempty"`
	DefaultProfile string                    `json:"default_profile,omitempty"`
	ActiveProfile  string                    `json:"-"` // Set at runtime, not persisted

	// Auth settings
	Scope string `json:"scope"`

	// Cache settings
	CacheDir     string `json:"cache_dir"`
	CacheEnabled bool   `json:"cache_enabled"`

	// Output settings
	Format string `json:"format"`

	// Behavior preferences (persisted via config set, overridable by flags)
	Hints   *bool `json:"hints,omitempty"`
	Stats   *bool `json:"stats,omitempty"`
	Verbose *int  `json:"verbose,omitempty"`

	// Sources tracks where each value came from (for debugging).
	Sources map[string]string `json:"-"`
}

Config holds the resolved configuration.

func Default

func Default() *Config

Default returns the default configuration.

func Load

func Load(overrides FlagOverrides) (*Config, error)

Load loads configuration from all sources with proper precedence. Precedence: flags > env > local > repo > global > system > defaults

func (*Config) ApplyProfile

func (cfg *Config) ApplyProfile(name string) error

ApplyProfile overlays profile values onto the config.

This is the first pass of a two-pass precedence system:

Pass 1 (this method): Profile values unconditionally overwrite config fields.
Pass 2 (caller):      LoadFromEnv + ApplyOverrides re-apply env vars and CLI
                       flags, which take final precedence over profile values.

The caller in root.go MUST call LoadFromEnv and ApplyOverrides after this method to maintain the precedence chain: flags > env > profile > file > defaults.

type FlagOverrides

type FlagOverrides struct {
	Account  string
	Project  string
	Todolist string
	Profile  string
	CacheDir string
	Format   string
}

FlagOverrides holds command-line flag values.

type ProfileConfig

type ProfileConfig struct {
	BaseURL    string `json:"base_url"`
	AccountID  string `json:"account_id,omitempty"`
	ProjectID  string `json:"project_id,omitempty"`
	TodolistID string `json:"todolist_id,omitempty"`
	Scope      string `json:"scope,omitempty"`
	ClientID   string `json:"client_id,omitempty"`
}

ProfileConfig holds configuration for a named profile.

type Source

type Source string

Source indicates where a config value came from.

const (
	SourceDefault Source = "default"
	SourceSystem  Source = "system"
	SourceGlobal  Source = "global"
	SourceRepo    Source = "repo"
	SourceLocal   Source = "local"
	SourceEnv     Source = "env"
	SourceFlag    Source = "flag"
	SourcePrompt  Source = "prompt"
)

Jump to

Keyboard shortcuts

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