mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
feat: add --silent cmd flag
This commit is contained in:
+11
-6
@@ -1,7 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"log"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@@ -16,20 +16,25 @@ var runCmd = &cobra.Command{
|
|||||||
Example: ` $ httpboomer run demo.json # run specified json testcase file
|
Example: ` $ httpboomer run demo.json # run specified json testcase file
|
||||||
$ httpboomer run demo.yaml # run specified yaml testcase file
|
$ httpboomer run demo.yaml # run specified yaml testcase file
|
||||||
$ httpboomer run examples/ # run testcases in specified folder`,
|
$ httpboomer run examples/ # run testcases in specified folder`,
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
// --silent flag
|
||||||
// f, _ := cmd.Flags().GetBool("gen-html-report")
|
silentFlag, err := cmd.Flags().GetBool("silent")
|
||||||
// fmt.Println(f)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Printf("[runCmd] set --silent flag: %v", silentFlag)
|
||||||
|
|
||||||
var paths []httpboomer.ITestCase
|
var paths []httpboomer.ITestCase
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
|
paths = append(paths, &httpboomer.TestCasePath{Path: arg})
|
||||||
}
|
}
|
||||||
return httpboomer.Run(&testing.T{}, paths...)
|
return httpboomer.NewRunner().SetDebug(!silentFlag).Run(paths...)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(runCmd)
|
rootCmd.AddCommand(runCmd)
|
||||||
runCmd.Flags().BoolP("gen-html-report", "r", false, "Generate HTML report")
|
runCmd.Flags().BoolP("silent", "s", false, "Disable logging request & response details")
|
||||||
|
// runCmd.Flags().BoolP("gen-html-report", "r", false, "Generate HTML report")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user