feat: exit with non-zero code on errors (#1218)
* feat: exit with non-zero code on errors * chore: use const for code
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
"github.com/tal-tech/go-zero/core/load"
|
"github.com/tal-tech/go-zero/core/load"
|
||||||
"github.com/tal-tech/go-zero/core/logx"
|
"github.com/tal-tech/go-zero/core/logx"
|
||||||
"github.com/tal-tech/go-zero/core/stat"
|
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/api/apigen"
|
"github.com/tal-tech/go-zero/tools/goctl/api/apigen"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/api/dartgen"
|
"github.com/tal-tech/go-zero/tools/goctl/api/dartgen"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/api/docgen"
|
"github.com/tal-tech/go-zero/tools/goctl/api/docgen"
|
||||||
@@ -36,6 +35,11 @@ import (
|
|||||||
pluginCtl "github.com/zeromicro/protobuf/protoc-gen-go"
|
pluginCtl "github.com/zeromicro/protobuf/protoc-gen-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
protocGenGoctl = "protoc-gen-goctl"
|
||||||
|
codeFailure = 1
|
||||||
|
)
|
||||||
|
|
||||||
var commands = []cli.Command{
|
var commands = []cli.Command{
|
||||||
{
|
{
|
||||||
Name: "upgrade",
|
Name: "upgrade",
|
||||||
@@ -646,28 +650,6 @@ var commands = []cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
logx.Disable()
|
|
||||||
load.Disable()
|
|
||||||
stat.DisableLog()
|
|
||||||
|
|
||||||
args := os.Args
|
|
||||||
pluginName := filepath.Base(args[0])
|
|
||||||
if pluginName == protocGenGoctl {
|
|
||||||
pluginCtl.Generate()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
app := cli.NewApp()
|
|
||||||
app.Usage = "a cli tool to generate code"
|
|
||||||
app.Version = fmt.Sprintf("%s %s/%s", version.BuildVersion, runtime.GOOS, runtime.GOARCH)
|
|
||||||
app.Commands = commands
|
|
||||||
// cli already print error messages
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
|
||||||
fmt.Println(aurora.Red(errorx.Wrap(err).Error()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := linkProtocGenGoctl()
|
err := linkProtocGenGoctl()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -675,8 +657,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const protocGenGoctl = "protoc-gen-goctl"
|
|
||||||
|
|
||||||
func linkProtocGenGoctl() error {
|
func linkProtocGenGoctl() error {
|
||||||
path, err := env.LookPath("goctl")
|
path, err := env.LookPath("goctl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -698,3 +678,26 @@ func linkProtocGenGoctl() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
logx.Disable()
|
||||||
|
load.Disable()
|
||||||
|
|
||||||
|
args := os.Args
|
||||||
|
pluginName := filepath.Base(args[0])
|
||||||
|
if pluginName == protocGenGoctl {
|
||||||
|
pluginCtl.Generate()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Usage = "a cli tool to generate code"
|
||||||
|
app.Version = fmt.Sprintf("%s %s/%s", version.BuildVersion, runtime.GOOS, runtime.GOARCH)
|
||||||
|
app.Commands = commands
|
||||||
|
|
||||||
|
// cli already print error messages
|
||||||
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
fmt.Println(aurora.Red(errorx.Wrap(err).Error()))
|
||||||
|
os.Exit(codeFailure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user