Correctly use the stdout parameter in some places

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č <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2023-01-11 21:52:20 +01:00
parent 4517ea0b7b
commit f17eafe85b
2 changed files with 5 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"os"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"text/template" "text/template"
@ -161,7 +160,7 @@ func (opts *inspectOptions) run(args []string, stdout io.Writer) (retErr error)
} else { } else {
row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}" row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}"
data = append(data, config) data = append(data, config)
err = printTmpl(row, data) err = printTmpl(stdout, row, data)
} }
if err != nil { if err != nil {
return fmt.Errorf("Error writing OCI-formatted configuration data to standard output: %w", err) 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}}" row := "{{range . }}" + report.NormalizeFormat(opts.format) + "{{end}}"
data = append(data, outputData) 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) t, err := template.New("skopeo inspect").Parse(row)
if err != nil { if err != nil {
return err return err
} }
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) w := tabwriter.NewWriter(stdout, 8, 2, 2, ' ', 0)
return t.Execute(w, data) return t.Execute(w, data)
} }

View File

@ -610,7 +610,7 @@ func (opts *syncOptions) run(args []string, stdout io.Writer) (retErr error) {
SignPassphrase: passphrase, SignPassphrase: passphrase,
SignBySigstorePrivateKeyFile: opts.signBySigstorePrivateKey, SignBySigstorePrivateKeyFile: opts.signBySigstorePrivateKey,
SignSigstorePrivateKeyPassphrase: []byte(passphrase), SignSigstorePrivateKeyPassphrase: []byte(passphrase),
ReportWriter: os.Stdout, ReportWriter: stdout,
DestinationCtx: destinationCtx, DestinationCtx: destinationCtx,
ImageListSelection: imageListSelection, ImageListSelection: imageListSelection,
PreserveDigests: opts.preserveDigests, PreserveDigests: opts.preserveDigests,