From 86e55e31f6905ae997619aa095706674e2ffe623 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Wed, 16 Sep 2026 00:55:01 +0200 Subject: explain reports captures and the chain a file would get --- internal/engine/plan.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'internal/engine/plan.go') diff --git a/internal/engine/plan.go b/internal/engine/plan.go index d9ffeb3..f2d6312 100644 --- a/internal/engine/plan.go +++ b/internal/engine/plan.go @@ -42,19 +42,26 @@ func (e *Engine) Plan(ctx context.Context, d *Dir, claims *plan.Claims) (*DirPla inputs := make([]plan.Input, len(r.Matched)) for i, fm := range r.Matched { - rules := make([]plan.RuleMatch, len(fm.Rules)) - for j, rm := range fm.Rules { - rules[j] = plan.RuleMatch{ - Name: rm.Rule.Name, - Actions: rm.Rule.Conf.Actions, - Settings: rm.Rule.Settings, - Captures: rm.Captures, - Reasons: rm.Reasons, - } - } - inputs[i] = plan.Input{File: fm.File, Rules: rules, NoDelete: fm.NoDelete} + inputs[i] = plan.Input{File: fm.File, Rules: planRules(fm.Rules), NoDelete: fm.NoDelete} } chains := plan.Build(d.Root, inputs, e.Now(), plan.OS{}, claims) return &DirPlan{Dir: d, Chains: chains, Result: r, Elapsed: time.Since(started)}, nil } + +// planRules converts a file's matching rules into what plan.Build takes. +// Explain builds the chain of one file the same way (GUI design ยง1.3), so +// both go through this. +func planRules(matched []RuleMatch) []plan.RuleMatch { + rules := make([]plan.RuleMatch, len(matched)) + for i, rm := range matched { + rules[i] = plan.RuleMatch{ + Name: rm.Rule.Name, + Actions: rm.Rule.Conf.Actions, + Settings: rm.Rule.Settings, + Captures: rm.Captures, + Reasons: rm.Reasons, + } + } + return rules +} -- cgit v1.3