Skip to content

Commit

Permalink
refactor: quiet output improve
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Mar 19, 2023
1 parent acff0ba commit 74d6613
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.go
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -31,8 +32,15 @@ func main() {
}

err := opt.Retry(cmd[0], cmd[1:])
if opt.Quiet {
fmt.Println()
}
if err != nil {
fmt.Println(err.Error())
if errors.As(err, &retry.Error{}) {
fmt.Println("All attempts fail")
} else {
fmt.Println(err.Error())
}
os.Exit(2)
}
}
Expand All @@ -55,8 +63,13 @@ func (o Option) Retry(cmd string, args []string) error {
},
retry.Attempts(o.Limit),
retry.Delay(o.Delay),
retry.DelayType(retry.FixedDelay),
retry.OnRetry(func(n uint, err error) {
fmt.Printf("--- failed %d time(s), err: %s ---\n", n+1, err)
if o.Quiet {
fmt.Print(".")
} else {
fmt.Printf("--- failed %d time(s), err: %s ---\n", n+1, err)
}
}),
)
}
Expand Down

0 comments on commit 74d6613

Please sign in to comment.