fix: use v.Stdout in isTerminal() instead of os.Stdout.Fd()
Convert isTerminal() from a standalone function to a method on Vaultik that checks whether v.Stdout implements Fd() (i.e. is an *os.File). Falls back to non-terminal for non-file writers (e.g. in tests). Eliminates all direct os.Stdout/os.Stderr references from restore.go.
This commit is contained in:
@@ -123,7 +123,7 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
||||
|
||||
// Create progress bar if output is a terminal
|
||||
var bar *progressbar.ProgressBar
|
||||
if isTerminal() {
|
||||
if v.isTerminal() {
|
||||
bar = progressbar.NewOptions64(
|
||||
totalBytesExpected,
|
||||
progressbar.OptionSetDescription("Restoring"),
|
||||
@@ -573,7 +573,7 @@ func (v *Vaultik) verifyRestoredFiles(
|
||||
|
||||
// Create progress bar if output is a terminal
|
||||
var bar *progressbar.ProgressBar
|
||||
if isTerminal() {
|
||||
if v.isTerminal() {
|
||||
bar = progressbar.NewOptions64(
|
||||
totalBytes,
|
||||
progressbar.OptionSetDescription("Verifying"),
|
||||
@@ -681,7 +681,16 @@ func (v *Vaultik) verifyFile(
|
||||
return bytesVerified, nil
|
||||
}
|
||||
|
||||
// isTerminal returns true if stdout is a terminal
|
||||
func isTerminal() bool {
|
||||
return term.IsTerminal(int(os.Stdout.Fd()))
|
||||
// isTerminal returns true if stdout is a terminal.
|
||||
// It checks whether v.Stdout implements Fd() (i.e. is an *os.File),
|
||||
// and falls back to false for non-file writers (e.g. in tests).
|
||||
func (v *Vaultik) isTerminal() bool {
|
||||
type fder interface {
|
||||
Fd() uintptr
|
||||
}
|
||||
f, ok := v.Stdout.(fder)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return term.IsTerminal(int(f.Fd()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user