mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 23:41:22 +08:00
support using curl as subcommand
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user