github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/prompts/smartops/helpers.go (about) 1 package smartopsPrompts 2 3 import ( 4 "os" 5 "path" 6 7 smartopsSchema "github.com/taubyte/go-project-schema/smartops" 8 structureSpec "github.com/taubyte/go-specs/structure" 9 "github.com/taubyte/tau-cli/flags" 10 "github.com/taubyte/tau-cli/prompts" 11 "github.com/taubyte/tau-cli/singletons/templates" 12 "github.com/urfave/cli/v2" 13 ) 14 15 // Should only be used in new, will overwrite values. 16 func checkTemplate(ctx *cli.Context, smartops *structureSpec.SmartOp) (templateURL string, err error) { 17 if !ctx.IsSet(flags.Template.Name) && !prompts.GetUseACodeTemplate(ctx) { 18 return 19 } 20 21 language, err := prompts.GetOrSelectLanguage(ctx) 22 if err != nil { 23 return 24 } 25 26 codeTemplateMap, err := templates.Get().SmartOps(language) 27 if err != nil { 28 return 29 } 30 31 templateURL, err = prompts.SelectATemplate(ctx, codeTemplateMap) 32 if err != nil { 33 return 34 } 35 36 file, err := os.ReadFile(path.Join(templateURL, "config.yaml")) 37 if err != nil { 38 return 39 } 40 41 getter, err := smartopsSchema.Yaml(smartops.Name, "", file) 42 if err != nil { 43 return 44 } 45 46 _smartops, err := getter.Struct() 47 if err != nil { 48 return 49 } 50 51 // Overwrite new smartops 52 *smartops = *_smartops 53 54 return 55 }