From 4cf0f5881d2b605b1ee3050cdc9636b41082dbd1 Mon Sep 17 00:00:00 2001 From: danbudris Date: Wed, 15 Sep 2021 19:39:58 -0400 Subject: [PATCH] make non-interactive `support-bundle` output more machine readable when using the `interactive=false` flag of `support-bundle`, the spinner would still spin and the archive path and analysis output were kind of smooshed together with the logs. now, if `interactive=false`, only print each recieved collector callback message once, and don't spin also, add a key to the archivePath and analyzerOutput that are returned, for easier programatic parsing --- cmd/troubleshoot/cli/run.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index e210572b..6a013df5 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -109,6 +109,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error { } s := spin.New() + interactive := v.GetBool("interactive") && isatty.IsTerminal(os.Stdout.Fd()) finishedCh := make(chan bool, 1) progressChan := make(chan interface{}) // non-zero buffer can result in missed messages isFinishedChClosed := false @@ -123,15 +124,22 @@ func runTroubleshoot(v *viper.Viper, arg string) error { c.Println(fmt.Sprintf("%s\r * %v", cursor.ClearEntireLine(), msg)) case string: currentDir = filepath.Base(msg) + if !interactive { + fmt.Printf("\rCollecting support bundle %s\n", currentDir) + } } case <-finishedCh: fmt.Printf("\r%s\r", cursor.ClearEntireLine()) return case <-time.After(time.Millisecond * 100): if currentDir == "" { - fmt.Printf("\r%s \033[36mCollecting support bundle\033[m %s", cursor.ClearEntireLine(), s.Next()) + if interactive { + fmt.Printf("\r%s \033[36mCollecting support bundle\033[m %s", cursor.ClearEntireLine(), s.Next()) + } } else { - fmt.Printf("\r%s \033[36mCollecting support bundle\033[m %s %s", cursor.ClearEntireLine(), s.Next(), currentDir) + if interactive { + fmt.Printf("\r%s \033[36mCollecting support bundle\033[m %s %s", cursor.ClearEntireLine(), s.Next(), currentDir) + } } } } @@ -177,8 +185,6 @@ func runTroubleshoot(v *viper.Viper, arg string) error { // Don't die } else if len(analyzeResults) > 0 { - interactive := v.GetBool("interactive") && isatty.IsTerminal(os.Stdout.Fd()) - if interactive { close(finishedCh) // this removes the spinner isFinishedChClosed = true @@ -194,7 +200,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error { c.Printf("%s\r * Failed to format analysis: %v\n", cursor.ClearEntireLine(), err) } - fmt.Printf("%s", formatted) + fmt.Printf("analyzerResults=%s\n", formatted) } } @@ -207,7 +213,7 @@ the %s Admin Console to begin analysis.` msg = fmt.Sprintf(f, appName, archivePath, appName) } - fmt.Printf("%s\n", msg) + fmt.Printf("archivePath=%s\n", msg) return nil }