Skip to content

Commit

Permalink
Add a spinner 😵‍💫
Browse files Browse the repository at this point in the history
  • Loading branch information
willdollman committed Oct 9, 2024
1 parent 051f223 commit 7328289
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/src/sbom_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,23 @@ Examples:
return err
}

fmt.Printf("Fetching SBOMs and validating signatures for all %d images in the Sourcegraph %s deployment...\n", len(images), c.version)
fmt.Printf("Fetching SBOMs and validating signatures for all %d images in the Sourcegraph %s release...\n", len(images), c.version)

var successCount, failureCount int
for _, image := range images {
stopSpinner := make(chan bool)
go spinner(image, stopSpinner)

_, err = c.getSBOMForImageVersion(image, c.version)

stopSpinner <- true

if err != nil {
out.WriteLine(output.Line(output.EmojiFailure, output.StyleWarning,
fmt.Sprintf("%s: error fetching and validating SBOM:\n %v", image, err)))
fmt.Sprintf("\r%s: error fetching and validating SBOM:\n %v", image, err)))
failureCount += 1
} else {
out.WriteLine(output.Line("\u2705", output.StyleSuccess, image))
out.WriteLine(output.Line("\r\u2705", output.StyleSuccess, image))
successCount += 1
}
}
Expand Down
17 changes: 17 additions & 0 deletions cmd/src/sbom_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os/exec"
"strings"
"time"
)

// Manifest represents a simplified structure of the Docker manifest response
Expand Down Expand Up @@ -191,3 +192,19 @@ func getGcloudAccessToken() (string, error) {
token := strings.TrimSpace(string(out))
return token, nil
}

var spinnerChars = []rune{'⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'}

func spinner(name string, stop chan bool) {
i := 0
for {
select {
case <-stop:
return
default:
fmt.Printf("\r%s %s", string(spinnerChars[i%len(spinnerChars)]), name)
i++
time.Sleep(100 * time.Millisecond)
}
}
}

0 comments on commit 7328289

Please sign in to comment.