You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package modelgen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/core/lang"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func FileModelCommand(c *cli.Context) error {
|
|
|
|
configFile := c.String("config")
|
|
|
|
if len(configFile) == 0 {
|
|
|
|
return errors.New("missing config value")
|
|
|
|
}
|
|
|
|
lang.Must(genModelWithConfigFile(configFile))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func CmdModelCommand(c *cli.Context) error {
|
|
|
|
address := c.String("address")
|
|
|
|
force := c.Bool("force")
|
|
|
|
schema := c.String("schema")
|
|
|
|
redis := c.Bool("redis")
|
|
|
|
if len(address) == 0 {
|
|
|
|
return errors.New("missing [-address|-a]")
|
|
|
|
}
|
|
|
|
if len(schema) == 0 {
|
|
|
|
return errors.New("missing [--schema|-s]")
|
|
|
|
}
|
|
|
|
addressArr := strings.Split(address, "@")
|
|
|
|
if len(addressArr) < 2 {
|
|
|
|
return errors.New("the address format is incorrect")
|
|
|
|
}
|
|
|
|
user := addressArr[0]
|
|
|
|
host := addressArr[1]
|
|
|
|
address = fmt.Sprintf("%v@tcp(%v)/information_schema", user, host)
|
|
|
|
lang.Must(genModelWithDataSource(address, schema, force, redis, nil))
|
|
|
|
return nil
|
|
|
|
}
|