@@ -13,11 +13,13 @@ import (
1313 "path/filepath"
1414 "time"
1515
16+ "github.com/ahmetalpbalkan/go-cursor"
1617 "github.com/mholt/archiver"
1718 troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
1819 collectrunner "github.com/replicatedhq/troubleshoot/pkg/collect"
1920 "github.com/replicatedhq/troubleshoot/pkg/logger"
2021 "github.com/spf13/viper"
22+ "github.com/tj/go-spin"
2123 "gopkg.in/yaml.v2"
2224 corev1 "k8s.io/api/core/v1"
2325 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -31,6 +33,9 @@ import (
3133)
3234
3335func runTroubleshootNoCRD (v * viper.Viper , arg string ) error {
36+ fmt .Print (cursor .Hide ())
37+ defer fmt .Print (cursor .Show ())
38+
3439 collectorContent := ""
3540 if ! isURL (arg ) {
3641 if _ , err := os .Stat (arg ); os .IsNotExist (err ) {
@@ -68,17 +73,43 @@ func runTroubleshootNoCRD(v *viper.Viper, arg string) error {
6873 return fmt .Errorf ("unable to parse %s collectors" , arg )
6974 }
7075
71- archivePath , err := runCollectors (v , collector )
76+ s := spin .New ()
77+ finishedCh := make (chan bool , 1 )
78+ progressChan := make (chan string , 1 )
79+ go func () {
80+ currentDir := ""
81+ for {
82+ select {
83+ case dir := <- progressChan :
84+ currentDir = filepath .Base (dir )
85+ case <- finishedCh :
86+ fmt .Printf ("\r " )
87+ return
88+ case <- time .After (time .Millisecond * 100 ):
89+ if currentDir == "" {
90+ fmt .Printf ("\r %s \033 [36mCollecting support bundle\033 [m %s" , cursor .ClearEntireLine (), s .Next ())
91+ } else {
92+ fmt .Printf ("\r %s \033 [36mCollecting support bundle\033 [m %s: %s" , cursor .ClearEntireLine (), s .Next (), currentDir )
93+ }
94+ }
95+ }
96+ }()
97+ defer func () {
98+ finishedCh <- true
99+ }()
100+
101+ archivePath , err := runCollectors (v , collector , progressChan )
72102 if err != nil {
73103 return err
74104 }
75105
106+ fmt .Printf ("\r %s" , cursor .ClearEntireLine ())
76107 fmt .Printf ("%s\n " , archivePath )
77108
78109 return nil
79110}
80111
81- func runCollectors (v * viper.Viper , collector troubleshootv1beta1.Collector ) (string , error ) {
112+ func runCollectors (v * viper.Viper , collector troubleshootv1beta1.Collector , progressChan chan string ) (string , error ) {
82113 cfg , err := config .GetConfig ()
83114 if err != nil {
84115 return "" , err
@@ -218,6 +249,7 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector) (str
218249 return
219250 }
220251
252+ progressChan <- collectorDir
221253 collectorDirs = append (collectorDirs , collectorDir )
222254
223255 if err := client .Delete (context .Background (), newPod ); err != nil {
0 commit comments