Skip to content

Commit 358d56c

Browse files
committed
feat(sync): replace summary sentence with progress bar output
Show sync results as a progress bar with an inline annotation instead of a separate summary sentence. Not-ready clusters are described with a full hint: "N clusters skipped (not ready — run with --include-not-ready to force)". Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
1 parent b1497f4 commit 358d56c

3 files changed

Lines changed: 64 additions & 62 deletions

File tree

‎cmd/bootstrap.go‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ import (
2020
)
2121

2222
var (
23-
bootstrapData string
24-
bootstrapServer string
25-
bootstrapOrg string
26-
bootstrapCAData string
27-
bootstrapIDPIssuerURL string
28-
bootstrapClientID string
29-
bootstrapClientSecret string
30-
bootstrapExtraScopes string
31-
bootstrapNamespace string
32-
bootstrapKubeconfig string
33-
bootstrapContextName string
34-
bootstrapSetCurrentCtx bool
35-
bootstrapDryRun bool
36-
bootstrapAuthType string
37-
bootstrapKubeloginPath string
38-
bootstrapKubeloginArgs []string
39-
bootstrapTokenCacheDir string
23+
bootstrapData string
24+
bootstrapServer string
25+
bootstrapOrg string
26+
bootstrapCAData string
27+
bootstrapIDPIssuerURL string
28+
bootstrapClientID string
29+
bootstrapClientSecret string
30+
bootstrapExtraScopes string
31+
bootstrapNamespace string
32+
bootstrapKubeconfig string
33+
bootstrapContextName string
34+
bootstrapSetCurrentCtx bool
35+
bootstrapDryRun bool
36+
bootstrapAuthType string
37+
bootstrapKubeloginPath string
38+
bootstrapKubeloginArgs []string
39+
bootstrapTokenCacheDir string
4040
)
4141

4242
func init() {

‎cmd/output/interactive_printer.go‎

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,37 @@ func (p *interactivePrinter) printSyncResult(r SyncResult) error {
199199
}
200200
}
201201

202+
// Progress bar (or empty-state message).
203+
if total == 0 {
204+
w("%s\n", styleFaint.Render("No clusters found to sync."))
205+
} else {
206+
const barWidth = 32
207+
filled := (r.Synced * barWidth) / total
208+
bar := styleGreen.Render(strings.Repeat("█", filled)) +
209+
styleFaint.Render(strings.Repeat("░", barWidth-filled))
210+
211+
var annotation string
212+
switch {
213+
case r.Failed > 0 && r.Skipped > 0:
214+
annotation = fmt.Sprintf("%s %s",
215+
styleFaint.Render(fmt.Sprintf("%d clusters skipped (not ready — run with --include-not-ready to force)", r.Skipped)),
216+
styleRed.Render(fmt.Sprintf("%d failed", r.Failed)),
217+
)
218+
case r.Failed > 0:
219+
annotation = styleRed.Render(fmt.Sprintf("%d failed", r.Failed))
220+
case r.Skipped > 0:
221+
annotation = styleFaint.Render(fmt.Sprintf("%d clusters skipped (not ready — run with --include-not-ready to force)", r.Skipped))
222+
default:
223+
annotation = styleGreen.Render("All clusters synced successfully.")
224+
}
225+
226+
w(" %s %s/%d %s · %s\n\n", bar,
227+
styleGreen.Render(fmt.Sprintf("%d", r.Synced)), total,
228+
styleBold.Render("Synced"),
229+
annotation,
230+
)
231+
}
232+
202233
if len(issues) > 0 {
203234
const (
204235
colCluster = 30
@@ -223,35 +254,6 @@ func (p *interactivePrinter) printSyncResult(r SyncResult) error {
223254
w("\n")
224255
}
225256

226-
// Summary sentence.
227-
var summary string
228-
switch {
229-
case total == 0:
230-
summary = styleFaint.Render("No clusters found to sync.")
231-
case r.Failed > 0 && r.Skipped > 0:
232-
summary = fmt.Sprintf("%s %s %s",
233-
styleGreen.Render(fmt.Sprintf("Synced %d of %d cluster(s).", r.Synced, total)),
234-
styleFaint.Render(fmt.Sprintf("%d not ready,", r.Skipped)),
235-
styleRed.Render(fmt.Sprintf("%d failed.", r.Failed)),
236-
)
237-
case r.Failed > 0:
238-
summary = fmt.Sprintf("%s %s",
239-
styleGreen.Render(fmt.Sprintf("Synced %d of %d cluster(s).", r.Synced, total)),
240-
styleRed.Render(fmt.Sprintf("%d failed.", r.Failed)),
241-
)
242-
case r.Skipped > 0:
243-
summary = fmt.Sprintf("%s %s",
244-
styleGreen.Render(fmt.Sprintf("Synced %d of %d cluster(s).", r.Synced, total)),
245-
styleFaint.Render(fmt.Sprintf("%d not ready.", r.Skipped)),
246-
)
247-
default:
248-
if total == 1 {
249-
summary = styleGreen.Render("Synced 1 cluster successfully.")
250-
} else {
251-
summary = styleGreen.Render(fmt.Sprintf("Synced all %d clusters successfully.", total))
252-
}
253-
}
254-
w("%s\n", summary)
255257
return writeErr
256258
}
257259

‎cmd/sync_test.go‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,34 +1060,34 @@ func TestResolveDisplaySources(t *testing.T) {
10601060
sep := string(os.PathListSeparator)
10611061

10621062
tests := []struct {
1063-
name string
1064-
explicitPath string
1065-
kubeconfig string
1066-
wantSources string
1063+
name string
1064+
explicitPath string
1065+
kubeconfig string
1066+
wantSources string
10671067
}{
10681068
{
1069-
name: "explicit path returned as-is",
1069+
name: "explicit path returned as-is",
10701070
explicitPath: "/explicit/kubeconfig",
1071-
kubeconfig: "/env/kubeconfig",
1072-
wantSources: "/explicit/kubeconfig",
1071+
kubeconfig: "/env/kubeconfig",
1072+
wantSources: "/explicit/kubeconfig",
10731073
},
10741074
{
1075-
name: "single KUBECONFIG entry returned as-is",
1075+
name: "single KUBECONFIG entry returned as-is",
10761076
explicitPath: "",
1077-
kubeconfig: "/single/kubeconfig",
1078-
wantSources: "/single/kubeconfig",
1077+
kubeconfig: "/single/kubeconfig",
1078+
wantSources: "/single/kubeconfig",
10791079
},
10801080
{
1081-
name: "multi-file KUBECONFIG: full list returned",
1081+
name: "multi-file KUBECONFIG: full list returned",
10821082
explicitPath: "",
1083-
kubeconfig: "/first" + sep + "/second" + sep + "/third",
1084-
wantSources: "/first" + sep + "/second" + sep + "/third",
1083+
kubeconfig: "/first" + sep + "/second" + sep + "/third",
1084+
wantSources: "/first" + sep + "/second" + sep + "/third",
10851085
},
10861086
{
1087-
name: "empty KUBECONFIG falls back to default",
1087+
name: "empty KUBECONFIG falls back to default",
10881088
explicitPath: "",
1089-
kubeconfig: "",
1090-
wantSources: clientcmd.RecommendedHomeFile,
1089+
kubeconfig: "",
1090+
wantSources: clientcmd.RecommendedHomeFile,
10911091
},
10921092
}
10931093

0 commit comments

Comments
 (0)