Fix unicode output on windows with redirect to file (#7358)

If we're not writing out to a terminal, avoid setting the console mode
on windows, which corrupts the output file.
This commit is contained in:
Daniel Hiltgen 2024-10-25 13:43:16 -07:00 committed by GitHub
parent 5231ae52d9
commit 35ec7f079f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1318,7 +1318,7 @@ func NewCLI() *cobra.Command {
log.SetFlags(log.LstdFlags | log.Lshortfile)
cobra.EnableCommandSorting = false
if runtime.GOOS == "windows" {
if runtime.GOOS == "windows" && term.IsTerminal(int(os.Stdout.Fd())) {
console.ConsoleFromFile(os.Stdin) //nolint:errcheck
}