support using curl as subcommand

This commit is contained in:
buyuxiang
2022-07-06 13:46:12 +08:00
parent 4b9705be22
commit a70b11401e
8 changed files with 347 additions and 210 deletions

View File

@@ -19,39 +19,7 @@ var convertCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
setLogLevel(logLevel)
},
RunE: func(cmd *cobra.Command, args []string) error {
var flagCount int
var outputType convert.OutputType
if toJSONFlag {
flagCount++
}
if toYAMLFlag {
flagCount++
outputType = convert.OutputTypeYAML
}
if toGoTestFlag {
flagCount++
outputType = convert.OutputTypeGoTest
}
if toPyTestFlag {
flagCount++
outputType = convert.OutputTypePyTest
packages := []string{
fmt.Sprintf("httprunner==%s", version.VERSION),
}
_, err := builtin.EnsurePython3Venv(venv, packages...)
if err != nil {
log.Error().Err(err).Msg("python3 venv is not ready")
return err
}
}
if flagCount > 1 {
return errors.New("please specify at most one conversion flag")
}
convert.Run(outputType, outputDir, profilePath, args)
return nil
},
RunE: convertRun,
}
var (
@@ -61,6 +29,8 @@ var (
toPyTestFlag bool
outputDir string
profilePath string
outputType convert.OutputType
)
func init() {
@@ -72,3 +42,36 @@ func init() {
convertCmd.Flags().StringVarP(&outputDir, "output-dir", "d", "", "specify output directory, default to the same dir with har file")
convertCmd.Flags().StringVarP(&profilePath, "profile", "p", "", "specify profile path to override headers and cookies")
}
func convertRun(cmd *cobra.Command, args []string) error {
var flagCount int
if toJSONFlag {
flagCount++
}
if toYAMLFlag {
flagCount++
outputType = convert.OutputTypeYAML
}
if toGoTestFlag {
flagCount++
outputType = convert.OutputTypeGoTest
}
if toPyTestFlag {
flagCount++
outputType = convert.OutputTypePyTest
packages := []string{
fmt.Sprintf("httprunner==%s", version.VERSION),
}
_, err := builtin.EnsurePython3Venv(venv, packages...)
if err != nil {
log.Error().Err(err).Msg("python3 venv is not ready")
return err
}
}
if flagCount > 1 {
return errors.New("please specify at most one conversion flag")
}
convert.Run(outputType, outputDir, profilePath, args)
return nil
}