@@ -3,6 +3,7 @@ package cmd
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "io"
6
7
"os"
7
8
"path"
8
9
"path/filepath"
@@ -30,6 +31,7 @@ type runOption struct {
30
31
limiter limit.RateLimiter
31
32
startTime time.Time
32
33
reporter runner.TestReporter
34
+ reportFile string
33
35
reportWriter runner.ReportResultWriter
34
36
report string
35
37
reportIgnore bool
@@ -72,17 +74,27 @@ See also https://github.com/LinuxSuRen/api-testing/tree/master/sample`,
72
74
flags .DurationVarP (& opt .duration , "duration" , "" , 0 , "Running duration" )
73
75
flags .DurationVarP (& opt .requestTimeout , "request-timeout" , "" , time .Minute , "Timeout for per request" )
74
76
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" )
75
79
flags .BoolVarP (& opt .reportIgnore , "report-ignore" , "" , false , "Indicate if ignore the report output" )
76
80
flags .Int64VarP (& opt .thread , "thread" , "" , 1 , "Threads of the execution" )
77
81
flags .Int32VarP (& opt .qps , "qps" , "" , 5 , "QPS" )
78
82
flags .Int32VarP (& opt .burst , "burst" , "" , 5 , "burst" )
79
- flags .StringVarP (& opt .report , "report" , "" , "" , "The type of target report. Supported: markdown, md, discard, std" )
80
83
return
81
84
}
82
85
83
86
func (o * runOption ) preRunE (cmd * cobra.Command , args []string ) (err error ) {
84
87
writer := cmd .OutOrStdout ()
85
88
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
+
86
98
switch o .report {
87
99
case "markdown" , "md" :
88
100
o .reportWriter = runner .NewMarkdownResultWriter (writer )
0 commit comments