mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-08 15:13:38 +08:00
fix: exit with code
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
@@ -20,5 +21,5 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
cmd.Execute()
|
||||
os.Exit(cmd.Execute())
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp/cmd/adb"
|
||||
"github.com/httprunner/httprunner/v4/hrp/cmd/ios"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||
)
|
||||
|
||||
@@ -45,7 +46,8 @@ Copyright 2017 debugtalk`,
|
||||
}
|
||||
},
|
||||
Version: version.VERSION,
|
||||
TraverseChildren: true,
|
||||
TraverseChildren: true, // parses flags on all parents before executing child command
|
||||
SilenceUsage: true, // silence usage when an error occurs
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -56,7 +58,7 @@ var (
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
func Execute() int {
|
||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||
rootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
||||
rootCmd.PersistentFlags().StringVar(&venv, "venv", "", "specify python3 venv path")
|
||||
@@ -64,9 +66,8 @@ func Execute() {
|
||||
ios.Init(rootCmd)
|
||||
adb.Init(rootCmd)
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
err := rootCmd.Execute()
|
||||
return code.GetErrorCode(err)
|
||||
}
|
||||
|
||||
func setLogLevel(level string) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v4/hrp"
|
||||
@@ -20,17 +18,14 @@ var runCmd = &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 {
|
||||
var paths []hrp.ITestCase
|
||||
for _, arg := range args {
|
||||
path := hrp.TestCasePath(arg)
|
||||
paths = append(paths, &path)
|
||||
}
|
||||
runner := makeHRPRunner()
|
||||
err := runner.Run(paths...)
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
return runner.Run(paths...)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user