feat(goctl): api dart support flutter v2 (#1603)
0. support null-safety code gen 1. supports -legacy flag for legacy code gen 2. supports -hostname flag for server hostname 3. use dart official format 4. fix some some bugs Resolves: #1602
This commit is contained in:
@@ -2,6 +2,7 @@ package dartgen
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
@@ -13,12 +14,18 @@ import (
|
||||
func DartCommand(c *cli.Context) error {
|
||||
apiFile := c.String("api")
|
||||
dir := c.String("dir")
|
||||
isLegacy := c.Bool("legacy")
|
||||
hostname := c.String("hostname")
|
||||
if len(apiFile) == 0 {
|
||||
return errors.New("missing -api")
|
||||
}
|
||||
if len(dir) == 0 {
|
||||
return errors.New("missing -dir")
|
||||
}
|
||||
if len(hostname) == 0 {
|
||||
fmt.Println("you could use '-hostname' flag to specify your server hostname")
|
||||
hostname = "go-zero.dev"
|
||||
}
|
||||
|
||||
api, err := parser.Parse(apiFile)
|
||||
if err != nil {
|
||||
@@ -30,8 +37,11 @@ func DartCommand(c *cli.Context) error {
|
||||
dir = dir + "/"
|
||||
}
|
||||
api.Info.Title = strings.Replace(apiFile, ".api", "", -1)
|
||||
logx.Must(genData(dir+"data/", api))
|
||||
logx.Must(genApi(dir+"api/", api))
|
||||
logx.Must(genVars(dir + "vars/"))
|
||||
logx.Must(genData(dir+"data/", api, isLegacy))
|
||||
logx.Must(genApi(dir+"api/", api, isLegacy))
|
||||
logx.Must(genVars(dir+"vars/", isLegacy, hostname))
|
||||
if err := formatDir(dir); err != nil {
|
||||
logx.Errorf("failed to format, %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user