Skip to content

Commit

Permalink
feat: flag code to stop re-executing when the process exits with the …
Browse files Browse the repository at this point in the history
…same exit code as provided
  • Loading branch information
ArunMurugan78 committed Jan 31, 2022
1 parent 33bce15 commit af5de0c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package cmd
type Config struct {
Timeout int
CommandString string
ExitCode int
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Run(config Config) {
for {
code := ExecuteCommand(config.CommandString)

if code == 0 {
if code == config.ExitCode {
break
}

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
}

timeout := flag.Int("timeout", 1000, "timeout after to retry in milliseconds")

exitCode := flag.Int("code", 0, "expected exit code to stop")
flag.Parse()

commandLineArgs := flag.CommandLine.Args()
Expand All @@ -36,6 +36,7 @@ func main() {
cmd.Run(cmd.Config{
Timeout: *timeout,
CommandString: Join(commandLineArgs),
ExitCode: *exitCode,
})

}
Expand Down

0 comments on commit af5de0c

Please sign in to comment.