feat: create python plugin in scaffold

This commit is contained in:
debugtalk
2022-03-18 17:59:59 +08:00
parent 5ad4bc3cce
commit c252549568
7 changed files with 272 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ package cmd
import (
"errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
@@ -22,7 +23,7 @@ var har2caseCmd = &cobra.Command{
for _, arg := range args {
// must choose one
if !genYAMLFlag && !genJSONFlag {
return errors.New("please select to-json flag or to-yaml flag.")
return errors.New("please select convert format type")
}
var outputPath string
var err error
@@ -37,7 +38,7 @@ var har2caseCmd = &cobra.Command{
if genYAMLFlag {
outputPath, err = har.GenYAML()
} else {
outputPath, err = har.GenJSON()
outputPath, err = har.GenJSON() // default
}
if err != nil {
return err

View File

@@ -1,8 +1,10 @@
package cmd
import (
"errors"
"os"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/httprunner/hrp/internal/scaffold"
@@ -15,14 +17,37 @@ var scaffoldCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
setLogLevel(logLevel)
},
Run: func(cmd *cobra.Command, args []string) {
err := scaffold.CreateScaffold(args[0])
RunE: func(cmd *cobra.Command, args []string) error {
if !ignorePlugin && !genPythonPlugin && !genGoPlugin {
return errors.New("please select function plugin type")
}
var pluginType scaffold.PluginType
if ignorePlugin {
pluginType = scaffold.Ignore
} else if genGoPlugin {
pluginType = scaffold.Go
} else {
pluginType = scaffold.Py // default
}
err := scaffold.CreateScaffold(args[0], pluginType)
if err != nil {
log.Error().Err(err).Msg("create scaffold project failed")
os.Exit(1)
}
return nil
},
}
var (
ignorePlugin bool
genPythonPlugin bool
genGoPlugin bool
)
func init() {
rootCmd.AddCommand(scaffoldCmd)
scaffoldCmd.Flags().BoolVar(&genPythonPlugin, "py", true, "generate hashicorp python plugin")
scaffoldCmd.Flags().BoolVar(&genGoPlugin, "go", false, "generate hashicorp go plugin")
scaffoldCmd.Flags().BoolVar(&ignorePlugin, "ignore-plugin", false, "ignore function plugin")
}