gunk-dev/the-valley

house_rules.go

source68d12192bbd3main's published tip history
911 bytes
1package cmd
2
3import (
4 "context"
5 "fmt"
6 "io"
7 "os"
8
9 "the-valley/flow/internal/config"
10 "the-valley/flow/internal/houserules"
11 "the-valley/flow/internal/project"
12)
13
14// loadHouseRules reads the house rules for work on the repo at repoRoot: the
15// repo's own .klaus/config.json may name other rules than the host config's
16// fallback. A missing file warns once and the work goes ahead without it.
17func loadHouseRules(ctx context.Context, repoRoot string, fallback config.Config, reg *project.Registry, info io.Writer) houserules.Rules {
18 cfg := fallback
19 if repoRoot != "" {
20 if c, err := config.Load(repoRoot); err == nil {
21 cfg = c
22 }
23 }
24 rules := houserules.Load(ctx, cfg.HouseRules, reg)
25 if w := rules.Warning(); w != "" {
26 fmt.Fprintf(os.Stderr, "warning: %s\n", w)
27 } else if rules.Digest != "" {
28 fmt.Fprintf(info, "House rules: %s (sha256 %.12s)\n", rules.Source, rules.Digest)
29 }
30 return rules
31}