-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_config.go
More file actions
71 lines (64 loc) · 1.7 KB
/
Copy pathmain_config.go
File metadata and controls
71 lines (64 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"os"
"path/filepath"
"quill-commit/config"
"quill-commit/git"
)
// ConfigResolver loads or creates quill.toml, applies preset and CLI overrides,
// and persists the config if anything changed.
type ConfigResolver struct {
CLI CLI
}
// Resolve returns the final config and the repo root.
func (r *ConfigResolver) Resolve() (cfg config.Config, repoRoot string, err error) {
repoRoot, err = git.RepoRoot()
if err != nil {
return config.Config{}, "", fmt.Errorf("get git repo root: %w", err)
}
configPath := filepath.Join(repoRoot, config.FileName)
cfg, created, err := config.EnsureDefault(configPath)
if err != nil {
return config.Config{}, "", err
}
if created {
fmt.Printf("created %s with defaults\n", configPath)
}
dirty := false
if r.CLI.Preset != "" {
if !config.ApplyPreset(&cfg, r.CLI.Preset) {
return config.Config{}, "", fmt.Errorf("unknown preset %q — valid presets: active, deep, aggressive", r.CLI.Preset)
}
dirty = true
}
if r.CLI.Model != "" {
cfg.Model = r.CLI.Model
dirty = true
}
if r.CLI.Interval > 0 {
cfg.Interval = r.CLI.Interval
dirty = true
}
if r.CLI.Stabilize > 0 {
cfg.Stabilize = r.CLI.Stabilize
dirty = true
}
if r.CLI.MaxDelays > 0 {
cfg.MaxDelays = r.CLI.MaxDelays
dirty = true
}
if r.CLI.Strategy != "" {
if !config.ValidStrategy(r.CLI.Strategy) {
return config.Config{}, "", fmt.Errorf("unknown strategy %q — valid values: permissive, standard, strict", r.CLI.Strategy)
}
cfg.Strategy = r.CLI.Strategy
dirty = true
}
if dirty {
if saveErr := config.Save(configPath, cfg); saveErr != nil {
fmt.Fprintf(os.Stderr, "warn: could not save config: %v\n", saveErr)
}
}
return cfg, repoRoot, nil
}