Skip to content

Commit

Permalink
refactor(commands): 🎨 Changed progress behavior in case of JSON output
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Sanino <alessandro@sanino.dev>
  • Loading branch information
saniales committed Jun 29, 2024
1 parent 3b53b17 commit 06a1ff7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func globalPreRunE(cmd *cobra.Command, args []string) error {
// executeInstall performs the "install" logic.
func executeInstall(cmd *cobra.Command, args []string) {
downloadProgressFunc := progressbarFunc
if globalFlags.json {
downloadProgressFunc = ttyFunc
}

httpClient := new(http.Client)
installer, err := install.NewInstallerWithProgressFunc(httpClient, downloadProgressFunc)
Expand Down Expand Up @@ -265,10 +268,10 @@ func ttyFunc(total int64, reader io.Reader) {
percentage := float64(totalRead) / float64(total) * 100

progressTTY := strings.Repeat("#", start) + strings.Repeat(".", end)
progressMessage := fmt.Sprintf("%s - %d%% completed", progressTTY, int(percentage))
progressMessage := fmt.Sprintf("%s - %d%% completed\n", progressTTY, int(percentage))
totalRead += int64(n)

fmt.Printf("\r%s", progressMessage)
slog.Info(progressMessage)

start++
end--
Expand Down

0 comments on commit 06a1ff7

Please sign in to comment.