Inspect fetches objects by reference using GetRefFunc and writes the json representation to the output writer.
(out io.Writer, references []string, tmplStr string, getRef GetRefFunc)
| 71 | // Inspect fetches objects by reference using GetRefFunc and writes the json |
| 72 | // representation to the output writer. |
| 73 | func Inspect(out io.Writer, references []string, tmplStr string, getRef GetRefFunc) error { |
| 74 | if out == nil { |
| 75 | return errors.New("no output stream") |
| 76 | } |
| 77 | inspector, err := NewTemplateInspectorFromString(out, tmplStr) |
| 78 | if err != nil { |
| 79 | return cli.StatusError{StatusCode: 64, Status: err.Error()} |
| 80 | } |
| 81 | |
| 82 | var errs []error |
| 83 | for _, ref := range references { |
| 84 | element, raw, err := getRef(ref) |
| 85 | if err != nil { |
| 86 | errs = append(errs, err) |
| 87 | continue |
| 88 | } |
| 89 | |
| 90 | if err := inspector.Inspect(element, raw); err != nil { |
| 91 | errs = append(errs, err) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if err := inspector.Flush(); err != nil { |
| 96 | logrus.Error(err) |
| 97 | } |
| 98 | |
| 99 | if err := errors.Join(errs...); err != nil { |
| 100 | return cli.StatusError{ |
| 101 | StatusCode: 1, |
| 102 | Status: err.Error(), |
| 103 | } |
| 104 | } |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | // Inspect executes the inspect template. |
| 109 | // It decodes the raw element into a map if the initial execution fails. |
nothing calls this directly
no test coverage detected
searching dependent graphs…