mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
refactor: move exec to myexec
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -23,7 +22,6 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/json"
|
||||
)
|
||||
|
||||
@@ -94,117 +92,6 @@ func FormatResponse(raw interface{}) interface{} {
|
||||
return formattedResponse
|
||||
}
|
||||
|
||||
var python3Executable string = "python3" // system default python3
|
||||
|
||||
// EnsurePython3Venv ensures python3 venv with specified packages
|
||||
// venv should be directory path of target venv
|
||||
func EnsurePython3Venv(venv string, packages ...string) (python3 string, err error) {
|
||||
// priority: specified > $HOME/.hrp/venv
|
||||
if venv == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "get user home dir failed")
|
||||
}
|
||||
venv = filepath.Join(home, ".hrp", "venv")
|
||||
}
|
||||
python3, err = ensurePython3Venv(venv, packages...)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "prepare python3 venv failed")
|
||||
}
|
||||
python3Executable = python3
|
||||
log.Info().Str("Python3Executable", python3Executable).Msg("set python3 executable path")
|
||||
return python3, nil
|
||||
}
|
||||
|
||||
func ExecPython3Command(cmdName string, args ...string) error {
|
||||
args = append([]string{"-m", cmdName}, args...)
|
||||
return ExecCommand(python3Executable, args...)
|
||||
}
|
||||
|
||||
func AssertPythonPackage(python3 string, pkgName, pkgVersion string) error {
|
||||
out, err := exec.Command(
|
||||
python3, "-c", fmt.Sprintf("import %s; print(%s.__version__)", pkgName, pkgName),
|
||||
).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("python package %s not found", pkgName)
|
||||
}
|
||||
|
||||
// do not check version if pkgVersion is empty
|
||||
if pkgVersion == "" {
|
||||
log.Info().Str("name", pkgName).Msg("python package is ready")
|
||||
return nil
|
||||
}
|
||||
|
||||
// check package version equality
|
||||
version := strings.TrimSpace(string(out))
|
||||
if strings.TrimLeft(version, "v") != strings.TrimLeft(pkgVersion, "v") {
|
||||
return fmt.Errorf("python package %s version %s not matched, please upgrade to %s",
|
||||
pkgName, version, pkgVersion)
|
||||
}
|
||||
|
||||
log.Info().Str("name", pkgName).Str("version", pkgVersion).Msg("python package is ready")
|
||||
return nil
|
||||
}
|
||||
|
||||
func InstallPythonPackage(python3 string, pkg string) (err error) {
|
||||
var pkgName, pkgVersion string
|
||||
if strings.Contains(pkg, "==") {
|
||||
// funppy==0.5.0
|
||||
pkgInfo := strings.Split(pkg, "==")
|
||||
pkgName = pkgInfo[0]
|
||||
pkgVersion = pkgInfo[1]
|
||||
} else {
|
||||
// funppy
|
||||
pkgName = pkg
|
||||
}
|
||||
|
||||
// check if package installed and version matched
|
||||
err = AssertPythonPackage(python3, pkgName, pkgVersion)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// check if pip available
|
||||
err = ExecCommand(python3, "-m", "pip", "--version")
|
||||
if err != nil {
|
||||
log.Warn().Msg("pip is not available")
|
||||
return errors.Wrap(err, "pip is not available")
|
||||
}
|
||||
|
||||
log.Info().Str("pkgName", pkgName).Str("pkgVersion", pkgVersion).Msg("installing python package")
|
||||
|
||||
// install package
|
||||
pypiIndexURL := env.PYPI_INDEX_URL
|
||||
if pypiIndexURL == "" {
|
||||
pypiIndexURL = "https://pypi.org/simple" // default
|
||||
}
|
||||
err = ExecCommand(python3, "-m", "pip", "install", "--upgrade", pkg,
|
||||
"--index-url", pypiIndexURL,
|
||||
"--quiet", "--disable-pip-version-check")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pip install package failed")
|
||||
}
|
||||
|
||||
return AssertPythonPackage(python3, pkgName, pkgVersion)
|
||||
}
|
||||
|
||||
func ExecCommandInDir(cmd *exec.Cmd, dir string) error {
|
||||
log.Info().Str("cmd", cmd.String()).Str("dir", dir).Msg("exec command")
|
||||
cmd.Dir = dir
|
||||
|
||||
// print output with colors
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("exec command failed")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateFolder(folderPath string) error {
|
||||
log.Info().Str("path", folderPath).Msg("create folder")
|
||||
err := os.MkdirAll(folderPath, os.ModePerm)
|
||||
@@ -289,19 +176,19 @@ func GetRandomNumber(min, max int) int {
|
||||
}
|
||||
|
||||
func Interface2Float64(i interface{}) (float64, error) {
|
||||
switch i.(type) {
|
||||
switch v := i.(type) {
|
||||
case int:
|
||||
return float64(i.(int)), nil
|
||||
return float64(v), nil
|
||||
case int32:
|
||||
return float64(i.(int32)), nil
|
||||
return float64(v), nil
|
||||
case int64:
|
||||
return float64(i.(int64)), nil
|
||||
return float64(v), nil
|
||||
case float32:
|
||||
return float64(i.(float32)), nil
|
||||
return float64(v), nil
|
||||
case float64:
|
||||
return i.(float64), nil
|
||||
return v, nil
|
||||
case string:
|
||||
intVar, err := strconv.Atoi(i.(string))
|
||||
intVar, err := strconv.Atoi(v)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -46,7 +46,7 @@ func DoCurl(args []string) (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
cmd := exec.Command("curl", args...)
|
||||
cmd := myexec.Command("curl", args...)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
@@ -60,11 +60,11 @@ func DoCurl(args []string) (err error) {
|
||||
return
|
||||
}
|
||||
if stdout.String() != "" {
|
||||
fmt.Printf(stdout.String())
|
||||
fmt.Println(stdout.String())
|
||||
curlResult.Result = stdout.String()
|
||||
curlResult.ResultType = normalResult
|
||||
} else if stderr.String() != "" {
|
||||
fmt.Printf(stderr.String())
|
||||
fmt.Println(stderr.String())
|
||||
curlResult.ErrorMsg = stderr.String()
|
||||
curlResult.ResultType = errorResult
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -51,7 +51,7 @@ func DoTraceRoute(traceRouteOptions *TraceRouteOptions, args []string) (err erro
|
||||
traceRouteTarget = strings.Split(parsedURL.Host, ":")[0]
|
||||
}
|
||||
|
||||
cmd := exec.Command("traceroute", "-m", strconv.Itoa(traceRouteOptions.MaxTTL),
|
||||
cmd := myexec.Command("traceroute", "-m", strconv.Itoa(traceRouteOptions.MaxTTL),
|
||||
"-q", strconv.Itoa(traceRouteOptions.Queries), traceRouteTarget)
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -49,7 +48,7 @@ func DoTraceRoute(traceRouteOptions *TraceRouteOptions, args []string) (err erro
|
||||
traceRouteTarget = strings.Split(parsedURL.Host, ":")[0]
|
||||
}
|
||||
|
||||
cmd := exec.Command("tracert", "-h", strconv.Itoa(traceRouteOptions.MaxTTL), traceRouteTarget)
|
||||
cmd := myexec.Command("tracert", "-h", strconv.Itoa(traceRouteOptions.MaxTTL), traceRouteTarget)
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
|
||||
startT := time.Now()
|
||||
|
||||
162
hrp/internal/myexec/cmd.go
Normal file
162
hrp/internal/myexec/cmd.go
Normal file
@@ -0,0 +1,162 @@
|
||||
package myexec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
)
|
||||
|
||||
var python3Executable string = "python3" // system default python3
|
||||
|
||||
func isPython3(python string) bool {
|
||||
out, err := Command(python, "--version").Output()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(string(out), "Python 3") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// EnsurePython3Venv ensures python3 venv with specified packages
|
||||
// venv should be directory path of target venv
|
||||
func EnsurePython3Venv(venv string, packages ...string) (python3 string, err error) {
|
||||
// priority: specified > $HOME/.hrp/venv
|
||||
if venv == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "get user home dir failed")
|
||||
}
|
||||
venv = filepath.Join(home, ".hrp", "venv")
|
||||
}
|
||||
python3, err = ensurePython3Venv(venv, packages...)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "prepare python3 venv failed")
|
||||
}
|
||||
python3Executable = python3
|
||||
log.Info().Str("Python3Executable", python3Executable).Msg("set python3 executable path")
|
||||
return python3, nil
|
||||
}
|
||||
|
||||
func ExecPython3Command(cmdName string, args ...string) error {
|
||||
args = append([]string{"-m", cmdName}, args...)
|
||||
return RunCommand(python3Executable, args...)
|
||||
}
|
||||
|
||||
func AssertPythonPackage(python3 string, pkgName, pkgVersion string) error {
|
||||
out, err := exec.Command(
|
||||
python3, "-c", fmt.Sprintf("import %s; print(%s.__version__)", pkgName, pkgName),
|
||||
).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("python package %s not found", pkgName)
|
||||
}
|
||||
|
||||
// do not check version if pkgVersion is empty
|
||||
if pkgVersion == "" {
|
||||
log.Info().Str("name", pkgName).Msg("python package is ready")
|
||||
return nil
|
||||
}
|
||||
|
||||
// check package version equality
|
||||
version := strings.TrimSpace(string(out))
|
||||
if strings.TrimLeft(version, "v") != strings.TrimLeft(pkgVersion, "v") {
|
||||
return fmt.Errorf("python package %s version %s not matched, please upgrade to %s",
|
||||
pkgName, version, pkgVersion)
|
||||
}
|
||||
|
||||
log.Info().Str("name", pkgName).Str("version", pkgVersion).Msg("python package is ready")
|
||||
return nil
|
||||
}
|
||||
|
||||
func InstallPythonPackage(python3 string, pkg string) (err error) {
|
||||
var pkgName, pkgVersion string
|
||||
if strings.Contains(pkg, "==") {
|
||||
// funppy==0.5.0
|
||||
pkgInfo := strings.Split(pkg, "==")
|
||||
pkgName = pkgInfo[0]
|
||||
pkgVersion = pkgInfo[1]
|
||||
} else {
|
||||
// funppy
|
||||
pkgName = pkg
|
||||
}
|
||||
|
||||
// check if package installed and version matched
|
||||
err = AssertPythonPackage(python3, pkgName, pkgVersion)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// check if pip available
|
||||
err = RunCommand(python3, "-m", "pip", "--version")
|
||||
if err != nil {
|
||||
log.Warn().Msg("pip is not available")
|
||||
return errors.Wrap(err, "pip is not available")
|
||||
}
|
||||
|
||||
log.Info().Str("pkgName", pkgName).Str("pkgVersion", pkgVersion).Msg("installing python package")
|
||||
|
||||
// install package
|
||||
pypiIndexURL := env.PYPI_INDEX_URL
|
||||
if pypiIndexURL == "" {
|
||||
pypiIndexURL = "https://pypi.org/simple" // default
|
||||
}
|
||||
err = RunCommand(python3, "-m", "pip", "install", "--upgrade", pkg,
|
||||
"--index-url", pypiIndexURL,
|
||||
"--quiet", "--disable-pip-version-check")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "pip install package failed")
|
||||
}
|
||||
|
||||
return AssertPythonPackage(python3, pkgName, pkgVersion)
|
||||
}
|
||||
|
||||
func RunCommand(cmdName string, args ...string) error {
|
||||
cmd := Command(cmdName, args...)
|
||||
log.Info().Str("cmd", cmd.String()).Msg("exec command")
|
||||
|
||||
// add cmd dir path to $PATH
|
||||
if cmdDir := filepath.Dir(cmdName); cmdDir != "" {
|
||||
path := fmt.Sprintf("%s:%s", cmdDir, env.PATH)
|
||||
if err := os.Setenv("PATH", path); err != nil {
|
||||
log.Error().Err(err).Msg("set env $PATH failed")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// print output with colors
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("exec command failed")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExecCommandInDir(cmd *exec.Cmd, dir string) error {
|
||||
log.Info().Str("cmd", cmd.String()).Str("dir", dir).Msg("exec command")
|
||||
cmd.Dir = dir
|
||||
|
||||
// print output with colors
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("exec command failed")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,31 +1,18 @@
|
||||
//go:build darwin || linux
|
||||
|
||||
package builtin
|
||||
package myexec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/env"
|
||||
)
|
||||
|
||||
func isPython3(python string) bool {
|
||||
out, err := exec.Command(python, "--version").Output()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(string(out), "Python 3") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getPython3Executable(venvDir string) string {
|
||||
return filepath.Join(venvDir, "bin", "python3")
|
||||
}
|
||||
@@ -42,20 +29,20 @@ func ensurePython3Venv(venv string, packages ...string) (python3 string, err err
|
||||
if !isPython3(python3) {
|
||||
// python3 venv not available, create one
|
||||
// check if system python3 is available
|
||||
if err := ExecCommand("python3", "--version"); err != nil {
|
||||
if err := RunCommand("python3", "--version"); err != nil {
|
||||
return "", errors.Wrap(err, "python3 not found")
|
||||
}
|
||||
|
||||
// check if .venv exists
|
||||
if _, err := os.Stat(venv); err == nil {
|
||||
// .venv exists, remove first
|
||||
if err := ExecCommand("rm", "-rf", venv); err != nil {
|
||||
if err := RunCommand("rm", "-rf", venv); err != nil {
|
||||
return "", errors.Wrap(err, "remove existed venv failed")
|
||||
}
|
||||
}
|
||||
|
||||
// create python3 .venv
|
||||
if err := ExecCommand("python3", "-m", "venv", venv); err != nil {
|
||||
if err := RunCommand("python3", "-m", "venv", venv); err != nil {
|
||||
return "", errors.Wrap(err, "create python3 venv failed")
|
||||
}
|
||||
}
|
||||
@@ -72,32 +59,13 @@ func ensurePython3Venv(venv string, packages ...string) (python3 string, err err
|
||||
}
|
||||
|
||||
func Command(name string, arg ...string) *exec.Cmd {
|
||||
args := strings.Join(arg, " ")
|
||||
return exec.Command("bash", "-c", name, args)
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func ExecCommand(cmdName string, args ...string) error {
|
||||
cmd := exec.Command(cmdName, args...)
|
||||
log.Info().Str("cmd", cmd.String()).Msg("exec command")
|
||||
|
||||
// add cmd dir path to $PATH
|
||||
if cmdDir := filepath.Dir(cmdName); cmdDir != "" {
|
||||
PATH := fmt.Sprintf("%s:%s", cmdDir, env.PATH)
|
||||
if err := os.Setenv("PATH", PATH); err != nil {
|
||||
log.Error().Err(err).Msg("set env $PATH failed")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// print output with colors
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("exec command failed")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
func KillProcessesByGpid(cmd *exec.Cmd) error {
|
||||
return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
//go:build windows
|
||||
|
||||
package builtin
|
||||
package myexec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
@@ -20,17 +16,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func isPython3(python string) bool {
|
||||
out, err := exec.Command("cmd", "/c", python, "--version").Output()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(string(out), "Python 3") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getPython3Executable(venvDir string) string {
|
||||
python := filepath.Join(venvDir, "Scripts", "python3.exe")
|
||||
if isPython3(python) {
|
||||
@@ -101,26 +86,17 @@ func ensurePython3Venv(venvDir string, packages ...string) (python3 string, err
|
||||
}
|
||||
|
||||
func Command(name string, arg ...string) *exec.Cmd {
|
||||
args := strings.Join(arg, " ")
|
||||
return exec.Command("cmd", "/c", name, args)
|
||||
}
|
||||
|
||||
func ExecCommand(cmdName string, args ...string) error {
|
||||
// "cmd /c" carries out the command specified by string and then stops
|
||||
// refer: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/cmd
|
||||
cmdStr := fmt.Sprintf("%s %s", cmdName, strings.Join(args, " "))
|
||||
cmd := exec.Command("cmd", "/c", cmdStr)
|
||||
log.Info().Str("cmd", cmd.String()).Msg("exec command")
|
||||
|
||||
// print output with colors
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("exec command failed")
|
||||
return err
|
||||
cmd := exec.Command("cmd.exe")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
CmdLine: strings.Join(append([]string{"/c", name}, arg...), " "),
|
||||
HideWindow: true,
|
||||
}
|
||||
|
||||
return nil
|
||||
return cmd
|
||||
}
|
||||
|
||||
func KillProcessesByGpid(cmd *exec.Cmd) error {
|
||||
killCmd := Command("taskkill", "/T", "/F", "/PID ", strconv.Itoa(cmd.Process.Pid))
|
||||
return killCmd.Run()
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package pytest
|
||||
|
||||
import (
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
)
|
||||
|
||||
@@ -12,5 +12,5 @@ func RunPytest(args []string) error {
|
||||
})
|
||||
|
||||
args = append([]string{"run"}, args...)
|
||||
return builtin.ExecPython3Command("httprunner", args...)
|
||||
return myexec.ExecPython3Command("httprunner", args...)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
@@ -177,7 +177,7 @@ func CreateScaffold(projectName string, pluginType PluginType, venv string, forc
|
||||
func createGoPlugin(projectName string) error {
|
||||
log.Info().Msg("start to create hashicorp go plugin")
|
||||
// check go sdk
|
||||
if err := builtin.ExecCommandInDir(exec.Command("go", "version"), projectName); err != nil {
|
||||
if err := myexec.RunCommand("go", "version"); err != nil {
|
||||
return errors.Wrap(err, "go sdk not installed")
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ func createPythonPlugin(projectName, venv string) error {
|
||||
fmt.Sprintf("funppy==%s", fungo.Version),
|
||||
fmt.Sprintf("httprunner==%s", version.VERSION),
|
||||
}
|
||||
_, err = builtin.EnsurePython3Venv(venv, packages...)
|
||||
_, err = myexec.EnsurePython3Venv(venv, packages...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/myexec"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/sdk"
|
||||
)
|
||||
|
||||
@@ -14,5 +13,5 @@ func OpenWiki() error {
|
||||
Action: "hrp wiki",
|
||||
})
|
||||
log.Info().Msgf("%s https://httprunner.com", openCmd)
|
||||
return exec.Command(openCmd, "https://httprunner.com").Run()
|
||||
return myexec.RunCommand(openCmd, "https://httprunner.com")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user