@@ -3,6 +3,7 @@ package cmd
33import (
44 "context"
55 "fmt"
6+ "io"
67 "os"
78 "path"
89 "path/filepath"
@@ -30,6 +31,7 @@ type runOption struct {
3031 limiter limit.RateLimiter
3132 startTime time.Time
3233 reporter runner.TestReporter
34+ reportFile string
3335 reportWriter runner.ReportResultWriter
3436 report string
3537 reportIgnore bool
@@ -72,17 +74,27 @@ See also https://github.com/LinuxSuRen/api-testing/tree/master/sample`,
7274 flags .DurationVarP (& opt .duration , "duration" , "" , 0 , "Running duration" )
7375 flags .DurationVarP (& opt .requestTimeout , "request-timeout" , "" , time .Minute , "Timeout for per request" )
7476 flags .BoolVarP (& opt .requestIgnoreError , "request-ignore-error" , "" , false , "Indicate if ignore the request error" )
77+ flags .StringVarP (& opt .report , "report" , "" , "" , "The type of target report. Supported: markdown, md, discard, std" )
78+ flags .StringVarP (& opt .reportFile , "report-file" , "" , "" , "The file path of the report" )
7579 flags .BoolVarP (& opt .reportIgnore , "report-ignore" , "" , false , "Indicate if ignore the report output" )
7680 flags .Int64VarP (& opt .thread , "thread" , "" , 1 , "Threads of the execution" )
7781 flags .Int32VarP (& opt .qps , "qps" , "" , 5 , "QPS" )
7882 flags .Int32VarP (& opt .burst , "burst" , "" , 5 , "burst" )
79- flags .StringVarP (& opt .report , "report" , "" , "" , "The type of target report. Supported: markdown, md, discard, std" )
8083 return
8184}
8285
8386func (o * runOption ) preRunE (cmd * cobra.Command , args []string ) (err error ) {
8487 writer := cmd .OutOrStdout ()
8588
89+ if o .reportFile != "" {
90+ var reportFile * os.File
91+ if reportFile , err = os .Create (o .reportFile ); err != nil {
92+ return
93+ }
94+
95+ writer = io .MultiWriter (writer , reportFile )
96+ }
97+
8698 switch o .report {
8799 case "markdown" , "md" :
88100 o .reportWriter = runner .NewMarkdownResultWriter (writer )
0 commit comments