v0.1.3 added unknown cli flag handling, dependency update
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
// FILE: lixenwraith/config/config.go
|
||||
// Package config provides thread-safe configuration management for Go applications
|
||||
// with support for multiple sources: TOML files, environment variables, command-line
|
||||
// arguments, and default values with configurable precedence.
|
||||
@@ -7,6 +6,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
@@ -50,6 +50,9 @@ type Config struct {
|
||||
version atomic.Int64
|
||||
structCache *structCache
|
||||
|
||||
// CLI paths that matched no registered path (reset on each CLI load)
|
||||
unknownCLIKeys []string
|
||||
|
||||
// File watching support
|
||||
watcher *watcher
|
||||
configFilePath string // Track loaded file path
|
||||
@@ -249,6 +252,7 @@ func (c *Config) SetSource(source Source, path string, value any) error {
|
||||
c.envData[path] = value
|
||||
case SourceCLI:
|
||||
c.cliData[path] = value
|
||||
c.unknownCLIKeys = nil
|
||||
}
|
||||
|
||||
c.invalidateCache() // Invalidate cache after changes
|
||||
@@ -337,6 +341,13 @@ func (c *Config) AsStruct() (any, error) {
|
||||
return c.structCache.target, nil
|
||||
}
|
||||
|
||||
// UnknownCLIKeys returns CLI paths that matched no registered config path
|
||||
func (c *Config) UnknownCLIKeys() []string {
|
||||
c.mutex.RLock()
|
||||
defer c.mutex.RUnlock()
|
||||
return slices.Clone(c.unknownCLIKeys)
|
||||
}
|
||||
|
||||
// computeValue determines the current value based on precedence
|
||||
func (c *Config) computeValue(item configItem) any {
|
||||
// Check sources in precedence order
|
||||
@@ -372,4 +383,4 @@ func (c *Config) populateStruct() error {
|
||||
// invalidateCache override Set methods to invalidate cache
|
||||
func (c *Config) invalidateCache() {
|
||||
c.version.Add(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user