From bcc0d54e5466f4d5ff13ba3a1ba696ff167309d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 27 Feb 2023 19:34:54 +0100 Subject: [PATCH] Simplify inspectOptions.writeOutput a bit more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't maintain a named array variable that we only append to exactly once. Should not change behavior. Signed-off-by: Miloslav Trmač --- cmd/skopeo/inspect.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/skopeo/inspect.go b/cmd/skopeo/inspect.go index 20ede748..e969caa4 100644 --- a/cmd/skopeo/inspect.go +++ b/cmd/skopeo/inspect.go @@ -217,12 +217,10 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error) return opts.writeOutput(stdout, outputData) } -// writeOutput writes outputData depending on opts.format to stdout -func (opts *inspectOptions) writeOutput(stdout io.Writer, outputData any) error { - var data []any - +// writeOutput writes data depending on opts.format to stdout +func (opts *inspectOptions) writeOutput(stdout io.Writer, data any) error { if report.IsJSON(opts.format) || opts.format == "" { - out, err := json.MarshalIndent(outputData, "", " ") + out, err := json.MarshalIndent(data, "", " ") if err == nil { fmt.Fprintf(stdout, "%s\n", string(out)) } @@ -234,6 +232,5 @@ func (opts *inspectOptions) writeOutput(stdout io.Writer, outputData any) error return err } defer rpt.Flush() - data = append(data, outputData) - return rpt.Execute(data) + return rpt.Execute([]any{data}) }