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

Function doTemplate

cli/template.go:155–209  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

153}
154
155func doTemplate(c *cli.Context) {
156 template := c.String("template")
157 manager := schema.GetManager()
158 configFile := c.String("config-file")
159 config := util.GetConfig()
160 err := config.ReadConfig(configFile)
161 if err != nil {
162 util.ExitFatal(err)
163 return
164 }
165 templateCode, err := util.GetContent(template)
166 if err != nil {
167 util.ExitFatal(err)
168 return
169 }
170 pwd, _ := os.Getwd()
171 os.Chdir(path.Dir(configFile))
172 defer os.Chdir(pwd)
173 schemaFiles := config.GetStringList("schemas", nil)
174 if schemaFiles == nil {
175 util.ExitFatal("No schema specified in configuration")
176 } else {
177 err = manager.LoadSchemasFromFiles(schemaFiles...)
178 if err != nil {
179 util.ExitFatal(err)
180 return
181 }
182 }
183 schemas := manager.OrderedSchemas()
184
185 if err != nil {
186 util.ExitFatal(err)
187 return
188 }
189 tpl, err := pongo2.FromString(string(templateCode))
190 if err != nil {
191 util.ExitFatal(err)
192 return
193 }
194 policies := manager.Policies()
195 policy := c.String("policy")
196 title := c.String("title")
197 version := c.String("version")
198 description := c.String("description")
199 outputPath := c.String("output-path")
200 schemasWithPolicy := filterSchemasForPolicy(policy, policies, schemas)
201 convertCustomActionOutput(schemasWithPolicy)
202 if c.IsSet("split-by-resource-group") {
203 applyTemplateForEachResourceGroup(schemasWithPolicy, tpl, version, description, outputPath)
204 } else if c.IsSet("split-by-resource") {
205 applyTemplateForEachResource(schemasWithPolicy, tpl, outputPath)
206 } else {
207 applyTemplateForAll(schemasWithPolicy, tpl, title, version, description, outputPath)
208 }
209}
210
211func convertCustomActionOutput(schemas []*SchemaWithPolicy) {
212 for _, schema := range schemas {

Callers

nothing calls this directly

Calls 12

filterSchemasForPolicyFunction · 0.85
applyTemplateForAllFunction · 0.85
ReadConfigMethod · 0.80
DirMethod · 0.80
GetStringListMethod · 0.80
LoadSchemasFromFilesMethod · 0.80
OrderedSchemasMethod · 0.80
PoliciesMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected