config

package
v0.0.0-...-f9a56e6 Latest Latest
Warning

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

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

Documentation

Overview

Package config handles configuration discovery, path resolution, and validation.

Index

Constants

This section is empty.

Variables

View Source
var SettingsRegistry = map[string]SettingInfo{
	"library_index": {Type: "string"},
	"default_agent": {Type: "string"},
	"shell":         {Type: "string"},
	"timeout":       {Type: "int"},
}

SettingsRegistry defines all valid settings keys and their types.

Functions

func CUEFilesInDir

func CUEFilesInDir(dir string) ([]string, error)

CUEFilesInDir returns a list of .cue files in the directory.

func LoadSettingsFromDir

func LoadSettingsFromDir(dir string) (map[string]string, error)

LoadSettingsFromDir loads settings from a specific directory.

func ResolveAllSettings

func ResolveAllSettings(paths Paths, localOnly bool) (map[string]SettingEntry, error)

ResolveAllSettings resolves all valid settings with their values and sources.

func SettingDefault

func SettingDefault(key string) string

SettingDefault returns the default value for a setting key. Returns empty string if the key has no default.

func ValidSettingsKeysString

func ValidSettingsKeysString() string

ValidSettingsKeysString returns a sorted, comma-separated list of valid setting keys.

Types

type Paths

type Paths struct {
	// Global is the path to the global config directory (~/.config/start/).
	Global string
	// Local is the path to the local config directory (./.start/).
	Local string
	// GlobalExists indicates whether the global config directory exists.
	GlobalExists bool
	// LocalExists indicates whether the local config directory exists.
	LocalExists bool
}

Paths holds the resolved configuration directory paths.

func ResolvePaths

func ResolvePaths(workingDir string) (Paths, error)

ResolvePaths discovers configuration directories. workingDir specifies the base directory for local config resolution. If workingDir is empty, the current working directory is used.

func (Paths) AnyExists

func (p Paths) AnyExists() bool

AnyExists returns true if any configuration directory exists.

func (Paths) Dir

func (p Paths) Dir(local bool) string

Dir returns the config directory for the given scope.

func (Paths) ForScope

func (p Paths) ForScope(scope Scope) []string

ForScope returns the paths that should be loaded for the given scope. Returns a slice of paths in load order (lowest priority first).

type Scope

type Scope int

Scope represents the configuration scope to load.

const (
	// ScopeMerged loads and merges both global and local configs.
	ScopeMerged Scope = iota
	// ScopeGlobal loads only global config (~/.config/start/).
	ScopeGlobal
	// ScopeLocal loads only local config (./.start/).
	ScopeLocal
)

func (Scope) String

func (s Scope) String() string

String returns the string representation of the scope.

type SettingEntry

type SettingEntry struct {
	Value  string `json:"value"`
	Source string `json:"source"` // "default", "global", "local", or "not set"
}

SettingEntry holds a resolved setting value and its source.

type SettingInfo

type SettingInfo struct {
	Type string // "string" or "int"
}

SettingInfo describes a valid settings key with its type.

type ValidationResult

type ValidationResult struct {
	// GlobalValid indicates the global config directory has valid CUE files.
	GlobalValid bool
	// LocalValid indicates the local config directory has valid CUE files.
	LocalValid bool
	// GlobalError contains the validation error for global config, if any.
	GlobalError *internalcue.ValidationError
	// LocalError contains the validation error for local config, if any.
	LocalError *internalcue.ValidationError
}

ValidationResult holds the result of validating configuration directories.

func ValidateConfig

func ValidateConfig(paths Paths) ValidationResult

ValidateConfig validates the CUE configuration in the given paths. It checks each directory that exists for valid CUE files. A directory is considered valid if it contains at least one .cue file that can be successfully parsed and loaded by CUE.

Empty directories (no .cue files) are treated as "no config" rather than errors. Only directories with invalid CUE files produce errors.

func (ValidationResult) AnyValid

func (r ValidationResult) AnyValid() bool

AnyValid returns true if at least one config location is valid.

func (ValidationResult) HasErrors

func (r ValidationResult) HasErrors() bool

HasErrors returns true if there are any validation errors.

Jump to

Keyboard shortcuts

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