MCPcopy Create free account
hub / github.com/cloudwan/gohan / gohanGenerate

Function gohanGenerate

cli/generate.go:86–193  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

84}
85
86func gohanGenerate(c *cli.Context) {
87 path := c.String("output")
88 templates := c.String("templates")
89 configFile := c.String("config-file")
90 packageName := c.String("package")
91 language := c.String("language")
92 dbName := c.String("dbname")
93 codeDir := filepath.Join(path, packageName)
94 etcDir := filepath.Join(path, "etc")
95 dbDir := filepath.Join(etcDir, "db")
96 resetDB := c.Bool("resetdb")
97 migrationDir := filepath.Join(dbDir, "migrations")
98 schemaPath := filepath.Join(etcDir, "schema.json")
99 manager := schema.GetManager()
100 config := util.GetConfig()
101 config.ReadConfig(configFile)
102 schemaFiles := config.GetStringList("schemas", nil)
103 if schemaFiles == nil {
104 log.Fatal("No schema specified in configuration")
105 return
106 }
107 if err := manager.LoadSchemasFromFiles(schemaFiles...); err != nil {
108 log.Fatal(err)
109 return
110 }
111 // Genrating schema json
112 log.Info("Genrating: schema json")
113
114 list := []interface{}{}
115
116 for _, schema := range manager.OrderedSchemas() {
117 if schema.IsAbstract() {
118 continue
119 }
120 if schema.Metadata["type"] == "metaschema" {
121 continue
122 }
123 s := schema.JSON()
124 s["url"] = schema.URL
125 list = append(list, s)
126 }
127 os.Mkdir(etcDir, 0777)
128 os.Mkdir(dbDir, 0777)
129 os.Mkdir(migrationDir, 0777)
130 execCommand(fmt.Sprintf("rm %s/*_init_schema.sql", migrationDir))
131 if resetDB {
132 err := ensureDatabase(dbName)
133 if err != nil {
134 log.Error("Failed to reset database", err)
135 }
136 }
137 execCommand(
138 fmt.Sprintf(
139 "gohan migrate init --config-file %s", configFile))
140 execCommand(
141 fmt.Sprintf(
142 "gohan migrate up --config-file %s", configFile))
143 // Running sqlboiler

Callers

nothing calls this directly

Calls 15

execCommandFunction · 0.85
ensureDatabaseFunction · 0.85
JoinMethod · 0.80
ReadConfigMethod · 0.80
GetStringListMethod · 0.80
FatalMethod · 0.80
LoadSchemasFromFilesMethod · 0.80
OrderedSchemasMethod · 0.80
IsAbstractMethod · 0.80
JSONMethod · 0.80
DirMethod · 0.80
FatalfMethod · 0.80

Tested by

no test coverage detected