config

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config manages CLI configuration with layered resolution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllKeyNames

func AllKeyNames() []string

AllKeyNames returns all config key names.

func CacheDir

func CacheDir() string

CacheDir returns the cache directory path (XDG_CACHE_HOME/microcms).

func ConfigDir

func ConfigDir() string

ConfigDir returns the config directory path (XDG_CONFIG_HOME/microcms).

func ConfigFilePath

func ConfigFilePath() string

ConfigFilePath returns the path to config.json.

func EnvOverrides

func EnvOverrides() map[string]string

EnvOverrides reads MICROCMS_* environment variables and returns config overrides.

func GetDotKey

func GetDotKey(cfg *Config, key string) (string, bool)

GetDotKey retrieves a value from config by dot-notation key.

func KeysByCategory

func KeysByCategory() map[string][]KeyMeta

KeysByCategory groups keys by their top-level category.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a duration string, returning an error with context.

func Save

func Save(cfg *Config) error

Save writes config to config.json atomically. Empty nested objects are removed to keep the file clean.

func SetDotKey

func SetDotKey(cfg *Config, key, value string) error

SetDotKey sets a value in config by dot-notation key.

func ToFlatMap

func ToFlatMap(cfg *Config) map[string]string

ToFlatMap converts config to a flat map with dot-notation keys.

func UnsetDotKey

func UnsetDotKey(cfg *Config, key string) error

UnsetDotKey removes a value from config by dot-notation key.

func Validate

func Validate(cfg *Config) error

Validate checks all config values and returns the first error found.

func ValidateKeyValue

func ValidateKeyValue(key, value string) error

ValidateKeyValue validates a single key-value pair.

Types

type BackupConfig

type BackupConfig struct {
	Parallelism           *int  `json:"parallelism,omitempty"`
	IncludeSchema         *bool `json:"includeSchema,omitempty"`
	IncludeManagementMeta *bool `json:"includeManagementMeta,omitempty"`
	DownloadMedia         *bool `json:"downloadMedia,omitempty"`
	Resume                *bool `json:"resume,omitempty"`
	FailFast              *bool `json:"failFast,omitempty"`
}

type Config

type Config struct {
	ActiveService string       `json:"activeService,omitempty"`
	HTTP          HTTPConfig   `json:"http,omitempty"`
	Output        OutputConfig `json:"output,omitempty"`
	Scan          ScanConfig   `json:"scan,omitempty"`
	Backup        BackupConfig `json:"backup,omitempty"`
	Log           LogConfig    `json:"log,omitempty"`
}

Config represents the full CLI configuration.

func Defaults

func Defaults() *Config

Defaults returns a Config with built-in default values.

func Load

func Load() (*Config, error)

Load reads config.json. Returns zero-value Config if file doesn't exist.

func Resolve

func Resolve(file *Config, envOverrides, flagOverrides map[string]string) *Config

Resolve merges config sources: defaults ← file ← env ← overrides.

type HTTPConfig

type HTTPConfig struct {
	Timeout string      `json:"timeout,omitempty"`
	Retry   RetryConfig `json:"retry,omitempty"`
}

type KeyMeta

type KeyMeta struct {
	Key         string
	Type        string // "string", "bool", "int", "duration", "enum", "[]int"
	EnvVar      string
	Description string
	Allowed     []string // For enum types
}

KeyMeta describes a config key with its type, env var, and description.

func AllKeys

func AllKeys() []KeyMeta

AllKeys returns all registered config keys.

func FindKey

func FindKey(key string) *KeyMeta

FindKey returns the KeyMeta for a dot-notation key, or nil if not found.

type LogConfig

type LogConfig struct {
	Level string `json:"level,omitempty"`
	HTTP  *bool  `json:"http,omitempty"`
}

type OutputConfig

type OutputConfig struct {
	Format string `json:"format,omitempty"`
	Pretty *bool  `json:"pretty,omitempty"`
	Color  string `json:"color,omitempty"`
}

type RetryConfig

type RetryConfig struct {
	Enabled      *bool  `json:"enabled,omitempty"`
	MaxAttempts  *int   `json:"maxAttempts,omitempty"`
	BaseInterval string `json:"baseInterval,omitempty"`
	MaxInterval  string `json:"maxInterval,omitempty"`
	Jitter       *bool  `json:"jitter,omitempty"`
	Policy       string `json:"policy,omitempty"`
	RetryOn      []int  `json:"retryOn,omitempty"`
}

type ScanConfig

type ScanConfig struct {
	AutoRefresh *bool  `json:"autoRefresh,omitempty"`
	TTL         string `json:"ttl,omitempty"`
}

Jump to

Keyboard shortcuts

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