diff options
| author | Claudomator Agent <agent@claudomator> | 2026-03-10 04:36:19 +0000 |
|---|---|---|
| committer | Claudomator Agent <agent@claudomator> | 2026-03-10 04:36:19 +0000 |
| commit | 8873187921c55d94be56364bf0b9d6b2d12127c2 (patch) | |
| tree | cc277db491104ebec5645e1a0422be9d5d4cafd2 /internal/config/config.go | |
| parent | 7d6943c5f9f4124c652377148a35bea5f61be4bf (diff) | |
cli: implement --config flag to load TOML config file
The --config flag was registered but silently ignored. Now:
- config.LoadFile loads a TOML file on top of defaults
- PersistentPreRunE applies the file when --config is set
- Explicit CLI flags (--data-dir, --claude-bin) take precedence over the file
Tests: TestLoadFile_OverridesDefaults, TestLoadFile_MissingFile_ReturnsError,
TestRootCmd_ConfigFile_Loaded, TestRootCmd_ConfigFile_CLIFlagOverrides,
TestRootCmd_ConfigFile_Missing_ReturnsError
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/config/config.go')
| -rw-r--r-- | internal/config/config.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index daf42fe..8c5aebf 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "path/filepath" + + "github.com/BurntSushi/toml" ) type Config struct { @@ -42,6 +44,19 @@ func Default() (*Config, error) { }, nil } +// LoadFile loads a TOML config file on top of the defaults. +// Fields not present in the file retain their default values. +func LoadFile(path string) (*Config, error) { + cfg, err := Default() + if err != nil { + return nil, err + } + if _, err := toml.DecodeFile(path, cfg); err != nil { + return nil, fmt.Errorf("loading config file %q: %w", path, err) + } + return cfg, nil +} + // EnsureDirs creates the data directory structure. func (c *Config) EnsureDirs() error { for _, dir := range []string{c.DataDir, c.LogDir} { |
