From f17eafe85b5c5f99d5956a4a06a4d2ea0ec25c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 11 Jan 2023 21:52:20 +0100 Subject: [PATCH] Correctly use the stdout parameter in some places MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should not change behavior - it would matter for unit tests which don't exist. Also, promptForPassphrase must continue to hard-code "real" os.Stdin and os.Stdout. Signed-off-by: Miloslav Trmač --- cmd/skopeo/inspect.go | 9 ++++----- cmd/skopeo/sync.go | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/skopeo/inspect.go b/cmd/skopeo/inspect.go index f18a8ef2..2cd82203 100644 --- a/cmd/skopeo/inspect.go +++ b/cmd/skopeo/inspect.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "os" "strings" "text/tabwriter" "text/template" @@ -161,7 +160,7 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error) } else { row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}" data = append(data, config) - err = printTmpl(row, data) + err = printTmpl(stdout, row, data) } if err != nil { return fmt.Errorf("Error writing OCI-formatted configuration data to standard output: %w", err) @@ -238,14 +237,14 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error) } row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}" data = append(data, outputData) - return printTmpl(row, data) + return printTmpl(stdout, row, data) } -func printTmpl(row string, data []interface{}) error { +func printTmpl(stdout io.Writer, row string, data []interface{}) error { t, err := template.New("skopeo inspect").Parse(row) if err != nil { return err } - w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) + w := tabwriter.NewWriter(stdout, 8, 2, 2, ' ', 0) return t.Execute(w, data) } diff --git a/cmd/skopeo/sync.go b/cmd/skopeo/sync.go index e4a5277c..8afbdbc6 100644 --- a/cmd/skopeo/sync.go +++ b/cmd/skopeo/sync.go @@ -610,7 +610,7 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) (retErr error) { SignPassphrase: passphrase, SignBySigstorePrivateKeyFile: opts.signBySigstorePrivateKey, SignSigstorePrivateKeyPassphrase: []byte(passphrase), - ReportWriter: os.Stdout, + ReportWriter: stdout, DestinationCtx: destinationCtx, ImageListSelection: imageListSelection, PreserveDigests: opts.preserveDigests,