Skip to content

Commit 2e062a6

Browse files
committed
fix(promrw): fix target parsing
1 parent bdcbe9f commit 2e062a6

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

cmd/promrw/bench.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"context"
77
"crypto/sha256"
8-
"flag"
98
"fmt"
109
"io"
1110
"math/rand"
@@ -495,19 +494,18 @@ func (s *Bench) prometheusConfig() *config {
495494
return cfg
496495
}
497496

498-
func (s *Bench) parseTargets() {
499-
for _, arg := range flag.Args() {
497+
func (s *Bench) parseTargets(args []string) error {
498+
for _, arg := range args {
500499
u, err := url.Parse(arg)
501500
if err != nil {
502-
fmt.Fprintln(os.Stderr, "invalid target:", err)
503-
os.Exit(1)
501+
return errors.Wrap(err, "parse url")
504502
}
505503
s.targets = append(s.targets, u.String())
506504
}
507505
if len(s.targets) == 0 {
508-
fmt.Fprintln(os.Stderr, "no targets specified")
509-
os.Exit(1)
506+
return errors.New("no targets")
510507
}
508+
return nil
511509
}
512510

513511
func (s *Bench) waitForTarget(ctx context.Context, target string) error {
@@ -697,8 +695,11 @@ func newBenchCommand() *cobra.Command {
697695
cmd := &cobra.Command{
698696
Use: "bench",
699697
Short: "Start remote write benchmark",
698+
Args: cobra.MinimumNArgs(1),
700699
RunE: func(cmd *cobra.Command, args []string) error {
701-
b.parseTargets()
700+
if err := b.parseTargets(args); err != nil {
701+
return err
702+
}
702703
return b.run(cmd.Context())
703704
},
704705
}

0 commit comments

Comments
 (0)