(f *File)
| 84 | } |
| 85 | |
| 86 | func (b *View) Apply(f *File) ([]ScopedValues, error) { |
| 87 | value, scalars, err := fileToValue(f) |
| 88 | if err != nil { |
| 89 | return nil, err |
| 90 | } |
| 91 | |
| 92 | resolver := newScalarResolver(scalars) |
| 93 | found := make([]ScopedValues, 0, len(b.Scopes)) |
| 94 | for _, s := range b.Scopes { |
| 95 | strs, serr := selectStrings(value, s.Expr) |
| 96 | if serr != nil { |
| 97 | return nil, fmt.Errorf("processing scope %q: %w", s.Name, serr) |
| 98 | } |
| 99 | values := make([]ScopedValue, 0, len(strs)) |
| 100 | for _, str := range strs { |
| 101 | line, col := resolver.locate(str) |
| 102 | values = append(values, ScopedValue{Text: str, Line: line, Column: col}) |
| 103 | } |
| 104 | found = append(found, ScopedValues{ |
| 105 | Scope: s.Name, |
| 106 | Values: values, |
| 107 | Format: s.Type, |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | return found, nil |
| 112 | } |
| 113 | |
| 114 | func selectStrings(value DaselValue, expr string) ([]string, error) { |
| 115 | selected, _, err := dasel.Select(context.Background(), value, expr) |
no test coverage detected