Skip to content

Commit 5915181

Browse files
authored
feat: Remove spinner (#2089)
Spinner is already available in a progressbar library we use (https://github.com/schollz/progressbar). Also it incoproates the same spinners available in https://github.com/briandowns/spinner Also, this fixes a bug where cursor was disappearing in the spinner library
1 parent 64b60fd commit 5915181

5 files changed

Lines changed: 14 additions & 26 deletions

File tree

cli/cmd/sync.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package cmd
33
import (
44
"context"
55
"fmt"
6-
"time"
76

8-
"github.com/briandowns/spinner"
97
"github.com/cloudquery/cloudquery/cli/internal/plugins"
108
"github.com/cloudquery/plugin-sdk/specs"
119
"github.com/rs/zerolog/log"
10+
"github.com/schollz/progressbar/v3"
1211
"github.com/spf13/cobra"
1312
"golang.org/x/sync/errgroup"
1413
)
@@ -118,11 +117,13 @@ func syncConnection(ctx context.Context, pm *plugins.PluginManager, sourceSpec s
118117
return nil
119118
})
120119

121-
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
122-
startTime := time.Now()
123-
format := " Syncing (%d resources) %s"
124-
s.Suffix = fmt.Sprintf(format, 0, time.Duration(0))
125-
s.Start()
120+
bar := progressbar.NewOptions(-1,
121+
progressbar.OptionSetDescription("Syncing resources..."),
122+
progressbar.OptionSetItsString("resources/sec"),
123+
progressbar.OptionShowIts(),
124+
progressbar.OptionSetElapsedTime(true),
125+
progressbar.OptionShowCount(),
126+
)
126127
failedWrites := uint64(0)
127128
totalResources := 0
128129
for i, destination := range sourceSpec.Destinations {
@@ -142,7 +143,7 @@ func syncConnection(ctx context.Context, pm *plugins.PluginManager, sourceSpec s
142143
g.Go(func() error {
143144
for resource := range resources {
144145
totalResources++
145-
s.Suffix = fmt.Sprintf(format, totalResources, time.Since(startTime).Truncate(time.Second))
146+
_ = bar.Add(1)
146147
for i := range destSubscriptions {
147148
select {
148149
case <-ctx.Done():
@@ -158,10 +159,10 @@ func syncConnection(ctx context.Context, pm *plugins.PluginManager, sourceSpec s
158159
})
159160

160161
if err := g.Wait(); err != nil {
161-
s.Stop()
162+
_ = bar.Finish()
162163
return fmt.Errorf("failed to fetch resources: %w", err)
163164
}
164-
s.Stop()
165+
_ = bar.Finish()
165166
fmt.Println("Fetch completed successfully.")
166167
fmt.Printf("Summary: Resources: %d, Failed Writes: %d, Fetch Errors: %d, Fetch Warnings: %d\n",
167168
totalResources, failedWrites, sourcePlugin.Errors(), sourcePlugin.Warnings())

cli/go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/cloudquery/cloudquery/cli
33
go 1.19
44

55
require (
6-
github.com/briandowns/spinner v1.19.0
76
github.com/cloudquery/plugin-sdk v0.9.0
87
github.com/getsentry/sentry-go v0.13.0
98
github.com/rs/zerolog v1.28.0
@@ -16,7 +15,6 @@ require (
1615

1716
require (
1817
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
19-
github.com/fatih/color v1.13.0 // indirect
2018
github.com/fsnotify/fsnotify v1.5.4 // indirect
2119
github.com/ghodss/yaml v1.0.0 // indirect
2220
github.com/gofrs/uuid v4.3.0+incompatible // indirect

cli/go.sum

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
3838
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3939
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4040
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
41-
github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E=
42-
github.com/briandowns/spinner v1.19.0/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU=
4341
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4442
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
4543
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
@@ -63,9 +61,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
6361
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
6462
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
6563
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
66-
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
67-
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
68-
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
6964
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
7065
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
7166
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
@@ -164,13 +159,9 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
164159
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
165160
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
166161
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
167-
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
168-
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
169162
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
170163
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
171164
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
172-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
173-
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
174165
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
175166
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
176167
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@@ -345,7 +336,6 @@ golang.org/x/sync v0.0.0-20220907140024-f12130a52804 h1:0SH2R3f1b1VmIMG7BXbEZCBU
345336
golang.org/x/sync v0.0.0-20220907140024-f12130a52804/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
346337
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
347338
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
348-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
349339
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
350340
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
351341
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -357,7 +347,6 @@ golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7w
357347
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
358348
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
359349
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
360-
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
361350
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
362351
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
363352
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

cli/internal/plugins/download.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/schollz/progressbar/v3"
1010
)
1111

12-
func downloadFile(filepath string, url string) (err error) {
12+
func downloadFile(filepath, url, description string) (err error) {
1313
// Create the file
1414
out, err := os.Create(filepath)
1515
if err != nil {
@@ -30,7 +30,7 @@ func downloadFile(filepath string, url string) (err error) {
3030
}
3131
bar := progressbar.DefaultBytes(
3232
resp.ContentLength,
33-
"Downloading",
33+
description,
3434
)
3535
// Writer the body to file
3636
_, err = io.Copy(io.MultiWriter(out, bar), resp.Body)

cli/internal/plugins/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (pm *PluginManager) downloadPluginFromGitHub(ctx context.Context, remotePat
230230
return "", fmt.Errorf("failed to create plugin directory %s: %w", downloadDir, err)
231231
}
232232

233-
err = downloadFile(pluginZipPath, downloadUrl)
233+
err = downloadFile(pluginZipPath, downloadUrl, "Downloading "+string(typ)+" plugin "+name+" version "+version)
234234
if err != nil {
235235
return "", fmt.Errorf("failed to download plugin: %w", err)
236236
}

0 commit comments

Comments
 (0)