mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user