Compare focused inspection views
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
yamladapter "go.maximumdirect.net/configkit/internal/yaml"
|
||||
@@ -25,6 +26,23 @@ func NewInspectionView(inspection *Inspection, scope Path) (InspectionView, bool
|
||||
|
||||
func (v InspectionView) Inspection() *Inspection { return v.inspection }
|
||||
|
||||
func (v InspectionView) Diff(other InspectionView) ([]Difference, error) {
|
||||
if v.inspection == nil || other.inspection == nil || v.scope.String() != other.scope.String() {
|
||||
return nil, errors.New("configkit: diff inspection scope unavailable or mismatched")
|
||||
}
|
||||
values, err := Diff(v.inspection, other.inspection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result []Difference
|
||||
for _, value := range values {
|
||||
if pathContains(v.scope, value.Path) || pathContains(value.Path, v.scope) {
|
||||
result = append(result, value)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (v InspectionView) WriteEffective(output io.Writer) error {
|
||||
if v.inspection == nil || v.inspection.final == nil || output == nil {
|
||||
return errEffectiveUnavailable
|
||||
|
||||
Reference in New Issue
Block a user