feat: add har2case flag

This commit is contained in:
debugtalk
2021-10-17 00:22:59 +08:00
parent 63cf798db1
commit d6b0ad6b8c
8 changed files with 4725 additions and 23 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ One-stop solution for HTTP(S) testing.
### Synopsis ### Synopsis
hrp (HttpRunnerPlus) is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨ hrp (HttpRunner+) is the next generation for HttpRunner. Enjoy! ✨ 🚀 ✨
License: Apache-2.0 License: Apache-2.0
Github: https://github.com/httprunner/hrp Github: https://github.com/httprunner/hrp
@@ -22,4 +22,4 @@ Copyright 2021 debugtalk
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files * [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
* [hrp run](hrp_run.md) - run API test * [hrp run](hrp_run.md) - run API test
###### Auto generated by spf13/cobra on 16-Oct-2021 ###### Auto generated by spf13/cobra on 17-Oct-2021
+1 -1
View File
@@ -37,4 +37,4 @@ hrp boom [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing. * [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 16-Oct-2021 ###### Auto generated by spf13/cobra on 17-Oct-2021
+4 -2
View File
@@ -13,11 +13,13 @@ hrp har2case path... [flags]
### Options ### Options
``` ```
-h, --help help for har2case -h, --help help for har2case
-j, --to-json convert to JSON format (default)
-y, --to-yaml convert to JSON format
``` ```
### SEE ALSO ### SEE ALSO
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing. * [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 16-Oct-2021 ###### Auto generated by spf13/cobra on 17-Oct-2021
+1 -1
View File
@@ -30,4 +30,4 @@ hrp run path... [flags]
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing. * [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
###### Auto generated by spf13/cobra on 16-Oct-2021 ###### Auto generated by spf13/cobra on 17-Oct-2021
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -11,7 +11,7 @@ import (
var harPath string var harPath string
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
harPath = "../examples/demo.har" harPath = "../examples/har/demo.har"
// run all tests // run all tests
code := m.Run() code := m.Run()
+22 -16
View File
@@ -1,7 +1,6 @@
package cmd package cmd
import ( import (
"fmt"
"log" "log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -14,27 +13,34 @@ var har2caseCmd = &cobra.Command{
Use: "har2case path...", Use: "har2case path...",
Short: "Convert HAR to json/yaml testcase files", Short: "Convert HAR to json/yaml testcase files",
Long: `Convert HAR to json/yaml testcase files`, Long: `Convert HAR to json/yaml testcase files`,
Run: func(cmd *cobra.Command, args []string) { Args: cobra.MinimumNArgs(1),
fmt.Println("har2case called") RunE: func(cmd *cobra.Command, args []string) error {
var outputFiles []string var outputFiles []string
for _, arg := range args { for _, arg := range args {
jsonPath, _ := har2case.NewHAR(arg).GenJSON() var outputPath string
outputFiles = append(outputFiles, jsonPath) var err error
if genYAMLFlag {
outputPath, err = har2case.NewHAR(arg).GenYAML()
} else {
outputPath, err = har2case.NewHAR(arg).GenJSON()
}
if err != nil {
return err
}
outputFiles = append(outputFiles, outputPath)
} }
log.Printf("%v", outputFiles) log.Printf("output: %v", outputFiles)
return nil
}, },
} }
var (
genJSONFlag bool
genYAMLFlag bool
)
func init() { func init() {
RootCmd.AddCommand(har2caseCmd) RootCmd.AddCommand(har2caseCmd)
har2caseCmd.Flags().BoolVarP(&genJSONFlag, "to-json", "j", false, "convert to JSON format (default)")
// Here you will define your flags and configuration settings. har2caseCmd.Flags().BoolVarP(&genYAMLFlag, "to-yaml", "y", false, "convert to JSON format")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// har2caseCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// har2caseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }