feat: specify output directory

This commit is contained in:
debugtalk
2021-10-17 00:46:17 +08:00
parent d6b0ad6b8c
commit cada3cf683
3 changed files with 56 additions and 19 deletions

View File

@@ -10,7 +10,7 @@ import (
// har2caseCmd represents the har2case command
var har2caseCmd = &cobra.Command{
Use: "har2case path...",
Use: "har2case harPath...",
Short: "Convert HAR to json/yaml testcase files",
Long: `Convert HAR to json/yaml testcase files`,
Args: cobra.MinimumNArgs(1),
@@ -19,10 +19,19 @@ var har2caseCmd = &cobra.Command{
for _, arg := range args {
var outputPath string
var err error
har := har2case.NewHAR(arg)
// specify output dir
if outputDir != "" {
har.SetOutputDir(outputDir)
}
// generate json/yaml files
if genYAMLFlag {
outputPath, err = har2case.NewHAR(arg).GenYAML()
outputPath, err = har.GenYAML()
} else {
outputPath, err = har2case.NewHAR(arg).GenJSON()
outputPath, err = har.GenJSON()
}
if err != nil {
return err
@@ -37,10 +46,12 @@ var har2caseCmd = &cobra.Command{
var (
genJSONFlag bool
genYAMLFlag bool
outputDir string
)
func init() {
RootCmd.AddCommand(har2caseCmd)
har2caseCmd.Flags().BoolVarP(&genJSONFlag, "to-json", "j", false, "convert to JSON format (default)")
har2caseCmd.Flags().BoolVarP(&genYAMLFlag, "to-yaml", "y", false, "convert to JSON format")
har2caseCmd.Flags().StringVarP(&outputDir, "output-dir", "d", "", "specify output directory, default to the same dir with har file")
}