Skip to content

Commit bbac469

Browse files
authored
fix: Progressbar related error when log-console option is used (#18161)
Goes with cloudquery/plugin-pb-go#336 ~needs cloudquery/plugin-pb-go#337 released~
1 parent fc4ff27 commit bbac469

15 files changed

Lines changed: 106 additions & 37 deletions

cli/cmd/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func installPlugin(cmd *cobra.Command, args []string) error {
6666
managedplugin.WithAuthToken(authToken.Value),
6767
managedplugin.WithTeamName(teamName),
6868
}
69+
if logConsole {
70+
opts = append(opts, managedplugin.WithNoProgress())
71+
}
6972
if cqDir != "" {
7073
opts = append(opts, managedplugin.WithDirectory(cqDir))
7174
}

cli/cmd/migrate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func migrate(cmd *cobra.Command, args []string) error {
7070
managedplugin.WithTeamName(teamName),
7171
managedplugin.WithLicenseFile(licenseFile),
7272
}
73+
if logConsole {
74+
opts = append(opts, managedplugin.WithNoProgress())
75+
}
7376
if cqDir != "" {
7477
opts = append(opts, managedplugin.WithDirectory(cqDir))
7578
}

cli/cmd/plugin_publish.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ func runPluginPublish(ctx context.Context, cmd *cobra.Command, args []string) er
157157

158158
func publishPluginAssets(ctx context.Context, c *cloudquery_api.ClientWithResponses, token, distDir string, pkgJSON publish.PackageJSONV1) error {
159159
if pkgJSON.PackageType == string(cloudquery_api.PluginPackageTypeDocker) {
160-
return publish.PublishToDockerRegistry(ctx, token, distDir, pkgJSON)
160+
return publish.PublishToDockerRegistry(ctx, token, distDir, pkgJSON, publish.Opts{
161+
NoProgress: logConsole,
162+
})
161163
}
162164

163165
return publish.PublishNativeBinaries(ctx, c, distDir, pkgJSON)

cli/cmd/progress.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import "io"
4+
5+
type progressBar interface {
6+
io.Writer
7+
Add(num int) error
8+
Finish() error
9+
}
10+
11+
type noopProgressBar struct {
12+
}
13+
14+
func (noopProgressBar) Write(p []byte) (int, error) {
15+
return len(p), nil
16+
}
17+
func (noopProgressBar) Add(_ int) error {
18+
return nil
19+
}
20+
func (noopProgressBar) Finish() error {
21+
return nil
22+
}

cli/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Find more information at:
2828
https://www.cloudquery.io`
2929

3030
disableSentry = false
31+
logConsole = false
3132
analyticsClient *AnalyticsClient
3233
logFile *os.File
3334
invocationUUID uuid.UUID
@@ -37,7 +38,6 @@ func NewCmdRoot() *cobra.Command {
3738
logLevel := enum.NewEnum([]string{"trace", "debug", "info", "warn", "error"}, "info")
3839
logFormat := enum.NewEnum([]string{"text", "json"}, "text")
3940
telemetryLevel := enum.NewEnum([]string{"none", "errors", "stats", "all"}, "all")
40-
logConsole := false
4141
noLogFile := false
4242
logFileName := "cloudquery.log"
4343
sentryDsn := sentryDsnDefault

cli/cmd/sync.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func sync(cmd *cobra.Command, args []string) error {
132132
managedplugin.WithTeamName(teamName),
133133
managedplugin.WithLicenseFile(licenseFile),
134134
}
135+
if logConsole {
136+
opts = append(opts, managedplugin.WithNoProgress())
137+
}
135138
if cqDir != "" {
136139
opts = append(opts, managedplugin.WithDirectory(cqDir))
137140
}
@@ -171,6 +174,9 @@ func sync(cmd *cobra.Command, args []string) error {
171174
managedplugin.WithTeamName(teamName),
172175
managedplugin.WithLicenseFile(licenseFile),
173176
}
177+
if logConsole {
178+
opts = append(opts, managedplugin.WithNoProgress())
179+
}
174180
if cqDir != "" {
175181
opts = append(opts, managedplugin.WithDirectory(cqDir))
176182
}

cli/cmd/sync_v1.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,18 @@ func syncConnectionV1(ctx context.Context, sourceClient *managedplugin.Client, d
124124
return err
125125
}
126126
}
127-
bar := progressbar.NewOptions(-1,
128-
progressbar.OptionSetDescription("Syncing resources..."),
129-
progressbar.OptionSetItsString("resources"),
130-
progressbar.OptionShowIts(),
131-
progressbar.OptionSetElapsedTime(true),
132-
progressbar.OptionShowCount(),
133-
progressbar.OptionClearOnFinish(),
134-
)
127+
128+
bar := progressBar(noopProgressBar{})
129+
if !logConsole {
130+
bar = progressbar.NewOptions(-1,
131+
progressbar.OptionSetDescription("Syncing resources..."),
132+
progressbar.OptionSetItsString("resources"),
133+
progressbar.OptionShowIts(),
134+
progressbar.OptionSetElapsedTime(true),
135+
progressbar.OptionShowCount(),
136+
progressbar.OptionClearOnFinish(),
137+
)
138+
}
135139

136140
// Add a ticker to update the progress bar every second.
137141
t := time.NewTicker(1 * time.Second)

cli/cmd/sync_v2.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"time"
10-
119
"slices"
10+
"time"
1211

1312
"github.com/cloudquery/cloudquery/cli/internal/specs/v0"
1413
"github.com/cloudquery/cloudquery/cli/internal/transformer"
@@ -185,14 +184,18 @@ func syncConnectionV2(ctx context.Context, sourceClient *managedplugin.Client, d
185184
return err
186185
}
187186
}
188-
bar := progressbar.NewOptions(-1,
189-
progressbar.OptionSetDescription("Syncing resources..."),
190-
progressbar.OptionSetItsString("resources"),
191-
progressbar.OptionShowIts(),
192-
progressbar.OptionSetElapsedTime(true),
193-
progressbar.OptionShowCount(),
194-
progressbar.OptionClearOnFinish(),
195-
)
187+
188+
bar := progressBar(noopProgressBar{})
189+
if !logConsole {
190+
bar = progressbar.NewOptions(-1,
191+
progressbar.OptionSetDescription("Syncing resources..."),
192+
progressbar.OptionSetItsString("resources"),
193+
progressbar.OptionShowIts(),
194+
progressbar.OptionSetElapsedTime(true),
195+
progressbar.OptionShowCount(),
196+
progressbar.OptionClearOnFinish(),
197+
)
198+
}
196199

197200
// Add a ticker to update the progress bar every second.
198201
t := time.NewTicker(1 * time.Second)

cli/cmd/sync_v3.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,17 @@ func syncConnectionV3(ctx context.Context, source v3source, destinations []v3des
186186
return err
187187
}
188188

189-
bar := progressbar.NewOptions(-1,
190-
progressbar.OptionSetDescription("Syncing resources..."),
191-
progressbar.OptionSetItsString("resources"),
192-
progressbar.OptionShowIts(),
193-
progressbar.OptionSetElapsedTime(true),
194-
progressbar.OptionShowCount(),
195-
progressbar.OptionClearOnFinish(),
196-
)
189+
bar := progressBar(noopProgressBar{})
190+
if !logConsole {
191+
bar = progressbar.NewOptions(-1,
192+
progressbar.OptionSetDescription("Syncing resources..."),
193+
progressbar.OptionSetItsString("resources"),
194+
progressbar.OptionShowIts(),
195+
progressbar.OptionSetElapsedTime(true),
196+
progressbar.OptionShowCount(),
197+
progressbar.OptionClearOnFinish(),
198+
)
199+
}
197200

198201
// Add a ticker to update the progress bar every 100ms
199202
t := time.NewTicker(100 * time.Millisecond)

cli/cmd/tables.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func tables(cmd *cobra.Command, args []string) error {
7979
managedplugin.WithAuthToken(authToken.Value),
8080
managedplugin.WithTeamName(teamName),
8181
}
82+
if logConsole {
83+
opts = append(opts, managedplugin.WithNoProgress())
84+
}
8285
if cqDir != "" {
8386
opts = append(opts, managedplugin.WithDirectory(cqDir))
8487
}

0 commit comments

Comments
 (0)