File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change 5
5
"bytes"
6
6
"context"
7
7
"crypto/sha256"
8
- "flag"
9
8
"fmt"
10
9
"io"
11
10
"math/rand"
@@ -495,19 +494,18 @@ func (s *Bench) prometheusConfig() *config {
495
494
return cfg
496
495
}
497
496
498
- func (s * Bench ) parseTargets () {
499
- for _ , arg := range flag . Args () {
497
+ func (s * Bench ) parseTargets (args [] string ) error {
498
+ for _ , arg := range args {
500
499
u , err := url .Parse (arg )
501
500
if err != nil {
502
- fmt .Fprintln (os .Stderr , "invalid target:" , err )
503
- os .Exit (1 )
501
+ return errors .Wrap (err , "parse url" )
504
502
}
505
503
s .targets = append (s .targets , u .String ())
506
504
}
507
505
if len (s .targets ) == 0 {
508
- fmt .Fprintln (os .Stderr , "no targets specified" )
509
- os .Exit (1 )
506
+ return errors .New ("no targets" )
510
507
}
508
+ return nil
511
509
}
512
510
513
511
func (s * Bench ) waitForTarget (ctx context.Context , target string ) error {
@@ -697,8 +695,11 @@ func newBenchCommand() *cobra.Command {
697
695
cmd := & cobra.Command {
698
696
Use : "bench" ,
699
697
Short : "Start remote write benchmark" ,
698
+ Args : cobra .MinimumNArgs (1 ),
700
699
RunE : func (cmd * cobra.Command , args []string ) error {
701
- b .parseTargets ()
700
+ if err := b .parseTargets (args ); err != nil {
701
+ return err
702
+ }
702
703
return b .run (cmd .Context ())
703
704
},
704
705
}
You can’t perform that action at this time.
0 commit comments