Skip to content

Commit 268ee37

Browse files
fix: direct CLI output to stdout instead of stderr (#121)
Fixes #120 Cobra's cmd.Print* methods default to stderr when no output writer is set. This causes commands like 'batt status' to write their output to stderr, making redirection (e.g., 'batt status > file.txt') capture nothing. Adding cmd.SetOut(os.Stdout) ensures normal command output goes to stdout while errors and diagnostics remain on stderr.
1 parent 96372f8 commit 268ee37

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cmd/batt/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ Report issues: https://github.com/charlie0129/batt/issues`,
136136
}
137137
}
138138

139+
// Direct cmd.Print* output to stdout instead of the default stderr.
140+
// This ensures normal command output (e.g., batt status) goes to stdout,
141+
// while only errors and diagnostics go to stderr.
142+
// See: https://github.com/charlie0129/batt/issues/120
143+
cmd.SetOut(os.Stdout)
144+
139145
globalFlags := cmd.PersistentFlags()
140146
globalFlags.StringVarP(&logLevel, "log-level", "l", logLevel, "log level (trace, debug, info, warn, error, fatal, panic)")
141147
globalFlags.StringVar(&configPath, "config", configPath, "config file path")

0 commit comments

Comments
 (0)