mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
hide spinner if interactive false (#328)
* hide preflight spinner if interactive is false Co-authored-by: Salah Aldeen Al Saleh <salahalsaleh1993@gmail.com>
This commit is contained in:
@@ -91,35 +91,37 @@ func runPreflights(v *viper.Viper, arg string) error {
|
||||
finishedCh := make(chan bool, 1)
|
||||
progressCh := make(chan interface{}, 0) // non-zero buffer will result in missed messages
|
||||
|
||||
s := spin.New()
|
||||
go func() {
|
||||
lastMsg := ""
|
||||
for {
|
||||
select {
|
||||
case msg, ok := <-progressCh:
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch msg := msg.(type) {
|
||||
case error:
|
||||
c := color.New(color.FgHiRed)
|
||||
c.Println(fmt.Sprintf("%s\r * %v", cursor.ClearEntireLine(), msg))
|
||||
case string:
|
||||
if lastMsg == msg {
|
||||
break
|
||||
if v.GetBool("interactive") {
|
||||
s := spin.New()
|
||||
go func() {
|
||||
lastMsg := ""
|
||||
for {
|
||||
select {
|
||||
case msg, ok := <-progressCh:
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
lastMsg = msg
|
||||
c := color.New(color.FgCyan)
|
||||
c.Println(fmt.Sprintf("%s\r * %s", cursor.ClearEntireLine(), msg))
|
||||
switch msg := msg.(type) {
|
||||
case error:
|
||||
c := color.New(color.FgHiRed)
|
||||
c.Println(fmt.Sprintf("%s\r * %v", cursor.ClearEntireLine(), msg))
|
||||
case string:
|
||||
if lastMsg == msg {
|
||||
break
|
||||
}
|
||||
lastMsg = msg
|
||||
c := color.New(color.FgCyan)
|
||||
c.Println(fmt.Sprintf("%s\r * %s", cursor.ClearEntireLine(), msg))
|
||||
}
|
||||
case <-time.After(time.Millisecond * 100):
|
||||
fmt.Printf("\r \033[36mRunning Preflight checks\033[m %s ", s.Next())
|
||||
case <-finishedCh:
|
||||
fmt.Printf("\r%s\r", cursor.ClearEntireLine())
|
||||
return
|
||||
}
|
||||
case <-time.After(time.Millisecond * 100):
|
||||
fmt.Printf("\r \033[36mRunning Preflight checks\033[m %s ", s.Next())
|
||||
case <-finishedCh:
|
||||
fmt.Printf("\r%s\r", cursor.ClearEntireLine())
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
defer func() {
|
||||
close(finishedCh)
|
||||
|
||||
Reference in New Issue
Block a user