Skip to content

Commit

Permalink
feat: support fail option
Browse files Browse the repository at this point in the history
  • Loading branch information
rxnew committed Sep 17, 2024
1 parent f07d8c8 commit edda103
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var opt struct {
Method string
Service string
Retry uint
Fail bool
}

var cmd = &cobra.Command{
Expand All @@ -45,6 +46,7 @@ func init() {
cmd.Flags().StringVarP(&opt.Method, "request", "X", "GET", "HTTP method [default: GET]")
cmd.Flags().StringVarP(&opt.Service, "service", "s", "execute-api", "AWS service name [default: execute-api]")
cmd.Flags().UintVar(&opt.Retry, "retry", 0, "Retry a specified number of times [default: 0]")
cmd.Flags().BoolVarP(&opt.Fail, "fail", "f", false, "Fail silently (no output at all) on HTTP errors")
}

func run(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -72,6 +74,11 @@ func run(cmd *cobra.Command, args []string) {
log.Fatalf("failed to read HTTP response body: %v", err)
}

if opt.Fail && resp.StatusCode >= 400 {
fmt.Printf("awscurl: (22) The requested URL returned error: %d\n", resp.StatusCode)
os.Exit(22)
}

fmt.Print(string(b))
}

Expand Down

0 comments on commit edda103

Please sign in to comment.