mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
change: add exit code
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -30,7 +29,7 @@ var boomCmd = &cobra.Command{
|
||||
}
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var paths []hrp.ITestCase
|
||||
for _, arg := range args {
|
||||
path := hrp.TestCasePath(arg)
|
||||
@@ -42,7 +41,7 @@ var boomCmd = &cobra.Command{
|
||||
err := builtin.LoadFile(boomArgs.profile, &boomArgs.Profile)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to load profile")
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +88,7 @@ var boomCmd = &cobra.Command{
|
||||
hrpBoomer.InitBoomer()
|
||||
hrpBoomer.Run(paths...)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -141,13 +141,13 @@ func init() {
|
||||
boomCmd.Flags().IntVar(&boomArgs.expectWorkersMaxWait, "expect-workers-max-wait", 120, "How many workers master should expect to connect before starting the test (only when --autostart is used")
|
||||
}
|
||||
|
||||
func makeHRPBoomer() *hrp.HRPBoomer {
|
||||
func makeHRPBoomer() (*hrp.HRPBoomer, error) {
|
||||
// if set profile, the priority is higher than the other commands
|
||||
if boomArgs.profile != "" {
|
||||
err := builtin.LoadFile(boomArgs.profile, &boomArgs)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to load profile")
|
||||
os.Exit(1)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
hrpBoomer := hrp.NewStandaloneBoomer(boomArgs.SpawnCount, boomArgs.SpawnRate)
|
||||
@@ -157,5 +157,5 @@ func makeHRPBoomer() *hrp.HRPBoomer {
|
||||
hrpBoomer.SetProfile(&boomArgs.Profile)
|
||||
hrpBoomer.EnableGracefulQuit(context.Background())
|
||||
hrpBoomer.InitBoomer()
|
||||
return hrpBoomer
|
||||
return hrpBoomer, nil
|
||||
}
|
||||
|
||||
@@ -21,11 +21,9 @@ var runCurlCmd = &cobra.Command{
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
runner := makeHRPRunner()
|
||||
if runner.Run(makeCurlTestCase(args)) != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
return runner.Run(makeCurlTestCase(args))
|
||||
},
|
||||
}
|
||||
|
||||
@@ -41,9 +39,13 @@ var boomCurlCmd = &cobra.Command{
|
||||
}
|
||||
setLogLevel(logLevel)
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
boomer := makeHRPBoomer()
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
boomer, err := makeHRPBoomer()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
boomer.Run(makeCurlTestCase(args))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -37,7 +36,7 @@ var scaffoldCmd = &cobra.Command{
|
||||
err := scaffold.CreateScaffold(args[0], pluginType, venv, force)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("create scaffold project failed")
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
log.Info().Str("projectName", args[0]).Msg("create scaffold success")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user