mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +08:00
feat: support force to overwrite existing project with --force/-f flag in hrp startproject
This commit is contained in:
@@ -36,4 +36,4 @@ Copyright 2017 debugtalk
|
||||
* [hrp run](hrp_run.md) - run API test with go engine
|
||||
* [hrp startproject](hrp_startproject.md) - create a scaffold project
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -41,4 +41,4 @@ hrp boom [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -18,4 +18,4 @@ hrp convert $path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -24,4 +24,4 @@ hrp har2case $har_path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -16,4 +16,4 @@ hrp pytest $path ... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -34,4 +34,4 @@ hrp run $path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -9,6 +9,7 @@ hrp startproject $project_name [flags]
|
||||
### Options
|
||||
|
||||
```
|
||||
-f, --force force to overwrite existing project
|
||||
--go generate hashicorp go plugin
|
||||
-h, --help help for startproject
|
||||
--ignore-plugin ignore function plugin
|
||||
@@ -19,4 +20,4 @@ hrp startproject $project_name [flags]
|
||||
|
||||
* [hrp](hrp.md) - Next-Generation API Testing Solution.
|
||||
|
||||
###### Auto generated by spf13/cobra on 22-Apr-2022
|
||||
###### Auto generated by spf13/cobra on 24-Apr-2022
|
||||
|
||||
@@ -2,4 +2,4 @@ module plugin
|
||||
|
||||
go 1.16
|
||||
|
||||
require github.com/httprunner/funplugin v0.4.2 // indirect
|
||||
require github.com/httprunner/funplugin v0.4.3 // indirect
|
||||
|
||||
@@ -58,8 +58,8 @@ github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v
|
||||
github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
|
||||
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||
github.com/httprunner/funplugin v0.4.2 h1:iDeg3GVCKdimgZQ40xq0kxHqhL/DQmRxs3DRjzOpUuo=
|
||||
github.com/httprunner/funplugin v0.4.2/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc=
|
||||
github.com/httprunner/funplugin v0.4.3 h1:mxdxQh54NZLQnK/FXZxpZV0rhqZQzckrWKEnBW5w2Vg=
|
||||
github.com/httprunner/funplugin v0.4.3/go.mod h1:vPyeJIfbpGe0epZZtAV0wCn16gLY9+imSw/zfxq0Lcc=
|
||||
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
|
||||
@@ -31,7 +31,7 @@ var scaffoldCmd = &cobra.Command{
|
||||
pluginType = scaffold.Py // default
|
||||
}
|
||||
|
||||
err := scaffold.CreateScaffold(args[0], pluginType)
|
||||
err := scaffold.CreateScaffold(args[0], pluginType, force)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("create scaffold project failed")
|
||||
os.Exit(1)
|
||||
@@ -45,10 +45,12 @@ var (
|
||||
ignorePlugin bool
|
||||
genPythonPlugin bool
|
||||
genGoPlugin bool
|
||||
force bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(scaffoldCmd)
|
||||
scaffoldCmd.Flags().BoolVarP(&force, "force", "f", false, "force to overwrite existing project")
|
||||
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")
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
package scaffold
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenDemoExamples(t *testing.T) {
|
||||
dir := "../../../examples/demo-with-go-plugin"
|
||||
os.RemoveAll(dir)
|
||||
err := CreateScaffold(dir, Go)
|
||||
err := CreateScaffold(dir, Go, true)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
dir = "../../../examples/demo-with-py-plugin"
|
||||
os.RemoveAll(dir)
|
||||
err = CreateScaffold(dir, Py)
|
||||
err = CreateScaffold(dir, Py, true)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
dir = "../../../examples/demo-without-plugin"
|
||||
os.RemoveAll(dir)
|
||||
err = CreateScaffold(dir, Ignore)
|
||||
err = CreateScaffold(dir, Ignore, true)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
@@ -42,25 +42,32 @@ func CopyFile(templateFile, targetFile string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateScaffold(projectName string, pluginType PluginType) error {
|
||||
func CreateScaffold(projectName string, pluginType PluginType, force bool) error {
|
||||
// report event
|
||||
sdk.SendEvent(sdk.EventTracking{
|
||||
Category: "Scaffold",
|
||||
Action: "hrp startproject",
|
||||
})
|
||||
|
||||
// check if projectName exists
|
||||
if _, err := os.Stat(projectName); err == nil {
|
||||
log.Warn().Str("projectName", projectName).
|
||||
Msg("project name already exists, please specify a new one.")
|
||||
return fmt.Errorf("project name already exists")
|
||||
}
|
||||
|
||||
log.Info().
|
||||
Str("projectName", projectName).
|
||||
Str("pluginType", string(pluginType)).
|
||||
Bool("force", force).
|
||||
Msg("create new scaffold project")
|
||||
|
||||
// check if projectName exists
|
||||
if _, err := os.Stat(projectName); err == nil {
|
||||
if !force {
|
||||
log.Warn().Str("projectName", projectName).
|
||||
Msg("project name already exists, please specify a new one.")
|
||||
return fmt.Errorf("project name already exists")
|
||||
}
|
||||
|
||||
log.Warn().Str("projectName", projectName).
|
||||
Msg("project name already exists, remove first !!!")
|
||||
os.RemoveAll(projectName)
|
||||
}
|
||||
|
||||
// create project folders
|
||||
if err := builtin.CreateFolder(projectName); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user