♲ Refactor configuration to use viper with context propagation

- Replace global ConfigPath and Overrides with viper-based configuration
- Add viper.New() to create configurable viper instances
- Store viper and unmarshaled Config struct in context for testability
- Add RetrieveFromContext and AddToContext helper functions
- Update files.Append to accept context and retrieve config from it
- Update formatters.Preferred and formatters.New to accept context
- Add PersistentPreRunE in CLI to create and configure viper instance
- Support -c flag for custom config file path
- Support -v flag for config value overrides
- Update all test files to create viper and add to context
- Remove unused config types and load functions
- Add viper as dependency with automatic env var support (MYLOG_*)
This commit is contained in:
Dan Jones 2026-03-08 22:59:33 -05:00
commit 9f05f933dd
21 changed files with 338 additions and 360 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright © 2024 Dan Jones <danjones@goodevilgenius.org>
Copyright © 2026 Dan Jones <danjones@goodevilgenius.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
@ -16,8 +16,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import "codeberg.org/danjones000/my-log/cli"
import (
"context"
"codeberg.org/danjones000/my-log/cli"
)
func main() {
cli.Execute()
cli.Execute(context.Background())
}