Skip to content

Commit

Permalink
fix: help message
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Mar 19, 2023
1 parent d675b10 commit 8140e9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@ Tool to execute terminal commands with retries.
## 💡 Idea

```bash
$ retry --limit=3 -- curl example.com
$ try [--limit=3 --delay=100ms] -- curl example.com
```

## 🤼‍♂️ How to

[![asciicast](https://asciinema.org/a/150367.png)](https://asciinema.org/a/150367)

```
Usage: retry --limit=N -- command
The strategy flags
-limit=N
Limit creates a Strategy that limits the number of attempts that Retry will make.
If N<=0, default value 3 will be used.
Usage: try [flags] -- command
Examples:
retry --limit=3 -- curl http://example.com
Flags:
--delay duration retry delay (default 100ms)
--limit uint max retry (default 5)
```
18 changes: 9 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import (
"github.com/spf13/pflag"
)

const reportTpl = `
retry --limit=4 -- curl ...
--`

func main() {
flags, cmd := partitionCommand(os.Args[1:])

var opt = Option{}

cli := pflag.NewFlagSet("try", pflag.ContinueOnError)
cli.UintVar(&opt.Limit, "limit", 5, "max retry")
cli.DurationVar(&opt.Delay, "delay", time.Millisecond*100, "retry delay")
flags, cmd := partitionCommand(os.Args[1:])
if len(cmd) == 0 {
// handle help message
fmt.Println("Usage: try [flags] -- command")
fmt.Println("\nflags:")
cli.PrintDefaults()
os.Exit(1)
}
if err := cli.Parse(flags); err != nil {
fmt.Println(err.Error())
os.Exit(1)
Expand Down Expand Up @@ -81,8 +82,7 @@ func partitionCommand(args []string) ([]string, []string) {
}

if splitIndex == -1 {
fmt.Println(reportTpl)
os.Exit(1)
return args, []string{}
}

return args[:splitIndex], args[splitIndex+1:]
Expand Down

0 comments on commit 8140e9e

Please sign in to comment.