termstatus: centralize OutputIsTerminal checks

This commit is contained in:
Michael Eischer committed 2025-10-03 18:55:46 +02:00
1 parent c745e4221e
commit 1ae2d08d1b
14 files changed
+85 -68

No files matched your search

+5 -6
View File
@@ -11,7 +11,6 @@ import (
"github.com/restic/restic/internal/dump"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/terminal"
"github.com/restic/restic/internal/ui"
"github.com/spf13/cobra"
@@ -180,7 +179,7 @@ func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args []
}
outputFileWriter := term.OutputRaw()
canWriteArchiveFunc := checkStdoutArchive
canWriteArchiveFunc := checkStdoutArchive(term)
if opts.Target != "" {
file, err := os.Create(opts.Target)
@@ -204,9 +203,9 @@ func runDump(ctx context.Context, opts DumpOptions, gopts GlobalOptions, args []
return nil
}
func checkStdoutArchive() error {
if terminal.StdoutIsTerminal() {
return fmt.Errorf("stdout is the terminal, please redirect output")
func checkStdoutArchive(term ui.Terminal) func() error {
if term.OutputIsTerminal() {
return func() error { return fmt.Errorf("stdout is the terminal, please redirect output") }
}
return nil
return func() error { return nil }
}