2020-07-29 17:11:41 +08:00
|
|
|
package validate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/logrusorgru/aurora"
|
2020-08-08 16:40:10 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/parser"
|
2020-07-29 17:11:41 +08:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// GoValidateApi verifies whether the api has a syntax error
|
2020-07-29 17:11:41 +08:00
|
|
|
func GoValidateApi(c *cli.Context) error {
|
|
|
|
apiFile := c.String("api")
|
|
|
|
|
|
|
|
if len(apiFile) == 0 {
|
|
|
|
return errors.New("missing -api")
|
|
|
|
}
|
|
|
|
|
2021-01-11 15:10:51 +08:00
|
|
|
_, err := parser.Parse(apiFile)
|
2020-07-29 17:11:41 +08:00
|
|
|
if err == nil {
|
|
|
|
fmt.Println(aurora.Green("api format ok"))
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|