From ca5b0c0249ca080f8fe123fd74feaa8f53d832cc Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 14 Sep 2025 15:29:39 +0200 Subject: [PATCH] get rid of fmt.Print* usages --- cmd/restic/cmd_features.go | 4 +--- cmd/restic/cmd_options.go | 4 ++-- cmd/restic/cmd_snapshots.go | 12 ++++-------- internal/filter/filter_test.go | 2 +- internal/restic/node_test.go | 3 +-- internal/selfupdate/verify.go | 3 +-- internal/walker/rewriter_test.go | 21 ++++++++++----------- 7 files changed, 20 insertions(+), 29 deletions(-) diff --git a/cmd/restic/cmd_features.go b/cmd/restic/cmd_features.go index 8541b1c34..e705ff080 100644 --- a/cmd/restic/cmd_features.go +++ b/cmd/restic/cmd_features.go @@ -1,8 +1,6 @@ package main import ( - "fmt" - "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/feature" "github.com/restic/restic/internal/ui/table" @@ -39,7 +37,7 @@ Exit status is 1 if there was any error. return errors.Fatal("the feature command expects no arguments") } - fmt.Printf("All Feature Flags:\n") + globalOptions.term.Print("All Feature Flags:\n") flags := feature.Flag.List() tab := table.New() diff --git a/cmd/restic/cmd_options.go b/cmd/restic/cmd_options.go index 86418c891..801beb5cd 100644 --- a/cmd/restic/cmd_options.go +++ b/cmd/restic/cmd_options.go @@ -24,7 +24,7 @@ Exit status is 1 if there was any error. GroupID: cmdGroupAdvanced, DisableAutoGenTag: true, Run: func(_ *cobra.Command, _ []string) { - fmt.Printf("All Extended Options:\n") + globalOptions.term.Print("All Extended Options:") var maxLen int for _, opt := range options.List() { if l := len(opt.Namespace + "." + opt.Name); l > maxLen { @@ -32,7 +32,7 @@ Exit status is 1 if there was any error. } } for _, opt := range options.List() { - fmt.Printf(" %*s %s\n", -maxLen, opt.Namespace+"."+opt.Name, opt.Text) + globalOptions.term.Print(fmt.Sprintf(" %*s %s", -maxLen, opt.Namespace+"."+opt.Name, opt.Text)) } }, } diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index 741da3331..7cbe06f5f 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -299,9 +299,7 @@ func PrintSnapshotGroupHeader(stdout io.Writer, groupKeyJSON string) error { } // Info - if _, err := fmt.Fprintf(stdout, "snapshots"); err != nil { - return err - } + header := "snapshots" var infoStrings []string if key.Hostname != "" { infoStrings = append(infoStrings, "host ["+key.Hostname+"]") @@ -313,12 +311,10 @@ func PrintSnapshotGroupHeader(stdout io.Writer, groupKeyJSON string) error { infoStrings = append(infoStrings, "paths ["+strings.Join(key.Paths, ", ")+"]") } if infoStrings != nil { - if _, err := fmt.Fprintf(stdout, " for (%s)", strings.Join(infoStrings, ", ")); err != nil { - return err - } + header += " for (" + strings.Join(infoStrings, ", ") + ")" } - _, err = fmt.Fprintf(stdout, ":\n") - + header += ":\n" + _, err = stdout.Write([]byte(header)) return err } diff --git a/internal/filter/filter_test.go b/internal/filter/filter_test.go index 59b4a4d2d..573c2ede6 100644 --- a/internal/filter/filter_test.go +++ b/internal/filter/filter_test.go @@ -389,7 +389,7 @@ func TestFilterPatternsFile(t *testing.T) { if match { c++ - // fmt.Printf("pattern %q, line %q\n", test.pattern, line) + // t.Logf("pattern %q, line %q\n", test.pattern, line) } } diff --git a/internal/restic/node_test.go b/internal/restic/node_test.go index 38a17cb09..b544b2afd 100644 --- a/internal/restic/node_test.go +++ b/internal/restic/node_test.go @@ -2,7 +2,6 @@ package restic import ( "encoding/json" - "fmt" "testing" "time" @@ -73,7 +72,7 @@ func TestSymlinkSerialization(t *testing.T) { var n2 Node err = json.Unmarshal(ser, &n2) test.OK(t, err) - fmt.Println(string(ser)) + t.Logf("serialized %q\n", string(ser)) test.Equals(t, n.LinkTarget, n2.LinkTarget) } diff --git a/internal/selfupdate/verify.go b/internal/selfupdate/verify.go index 8db93fe8b..558c27965 100644 --- a/internal/selfupdate/verify.go +++ b/internal/selfupdate/verify.go @@ -174,8 +174,7 @@ CwGc func GPGVerify(data, sig []byte) (ok bool, err error) { keyring, err := openpgp.ReadArmoredKeyRing(bytes.NewReader(key)) if err != nil { - fmt.Printf("reading keyring failed") - return false, err + return false, fmt.Errorf("reading keyring failed: %w", err) } _, err = openpgp.CheckArmoredDetachedSignature(keyring, bytes.NewReader(data), bytes.NewReader(sig)) diff --git a/internal/walker/rewriter_test.go b/internal/walker/rewriter_test.go index 58dd25cd0..7c613e4ae 100644 --- a/internal/walker/rewriter_test.go +++ b/internal/walker/rewriter_test.go @@ -2,7 +2,6 @@ package walker import ( "context" - "fmt" "testing" "github.com/pkg/errors" @@ -32,9 +31,9 @@ func (t WritableTreeMap) SaveBlob(_ context.Context, tpe restic.BlobType, buf [] return id, true, len(buf), nil } -func (t WritableTreeMap) Dump() { +func (t WritableTreeMap) Dump(test testing.TB) { for k, v := range t.TreeMap { - fmt.Printf("%v: %v", k, string(v)) + test.Logf("%v: %v", k, string(v)) } } @@ -294,10 +293,10 @@ func TestRewriter(t *testing.T) { // verifying against the expected tree root also implicitly checks the structural integrity if newRoot != expRoot { t.Error("hash mismatch") - fmt.Println("Got") - modrepo.Dump() - fmt.Println("Expected") - WritableTreeMap{expRepo}.Dump() + t.Log("Got") + modrepo.Dump(t) + t.Log("Expected") + WritableTreeMap{expRepo}.Dump(t) } }) } @@ -348,10 +347,10 @@ func TestSnapshotSizeQuery(t *testing.T) { // verifying against the expected tree root also implicitly checks the structural integrity if newRoot != expRoot { t.Error("hash mismatch") - fmt.Println("Got") - modrepo.Dump() - fmt.Println("Expected") - WritableTreeMap{expRepo}.Dump() + t.Log("Got") + modrepo.Dump(t) + t.Log("Expected") + WritableTreeMap{expRepo}.Dump(t) } })