Skip to content

Commit

Permalink
Fix error when num of CPU not match progress bars
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Aug 1, 2023
1 parent 6b61c2f commit f97f52f
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func runWatchStatus(writer io.Writer, client *daemonclient.Client, cacheDir stri
if err != nil {
return
}
} else if len(loadResult.CPUUse) > len(cpuBars) {
newCPUCount := len(loadResult.CPUUse) - len(cpuBars)
oldCpuCount := len(cpuBars)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (macOS-11, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (windows-2019, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (macOS-latest, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)

Check failure on line 95 in cmd/crc/cmd/status.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 1.19)

var-naming: var oldCpuCount should be oldCPUCount (revive)
for i := 0; i < newCPUCount; i++ {
bar := createCPUBar(oldCpuCount+i, writer)
barPull.Add(bar)
cpuBars = append(cpuBars, bar)
}
}

ramBar.SetTotal(loadResult.RAMSize)
Expand All @@ -111,19 +119,23 @@ func createBars(cpuUse []int64, writer io.Writer) (ramBar *pb.ProgressBar, cpuBa
ramBar.SetTemplateString(tmpl)

for i := range cpuUse {
bar := pb.New(101)
bar.SetWriter(writer)
bar.Set(pb.Static, true)
tmpl := fmt.Sprintf(`{{ green "CPU%d:" }} {{percent .}} {{string . "my_green_string" | green}} {{ bar . "[" "\u2588" "\u2588" " " "]"}}`, i)
bar.SetTemplateString(tmpl)
bar.SetMaxWidth(150)

bar := createCPUBar(i, writer)
cpuBars = append(cpuBars, bar)
}

return ramBar, cpuBars
}

func createCPUBar(cpuNum int, writer io.Writer) *pb.ProgressBar {
bar := pb.New(101)
bar.SetWriter(writer)
bar.Set(pb.Static, true)
tmpl := fmt.Sprintf(`{{ green "CPU%d:" }} {{percent .}} {{string . "my_green_string" | green}} {{ bar . "[" "\u2588" "\u2588" " " "]"}}`, cpuNum)
bar.SetTemplateString(tmpl)
bar.SetMaxWidth(150)
return bar
}

func getStatus(client *daemonclient.Client, cacheDir string) *status {

clusterStatus, err := client.APIClient.Status()
Expand Down

0 comments on commit f97f52f

Please sign in to comment.