github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/cli/commands/dream/build/function.go (about) 1 package build 2 3 import ( 4 "path" 5 6 commonSpec "github.com/taubyte/go-specs/common" 7 functionSpec "github.com/taubyte/go-specs/function" 8 dreamI18n "github.com/taubyte/tau-cli/i18n/dream" 9 applicationLib "github.com/taubyte/tau-cli/lib/application" 10 dreamLib "github.com/taubyte/tau-cli/lib/dream" 11 functionPrompts "github.com/taubyte/tau-cli/prompts/function" 12 "github.com/urfave/cli/v2" 13 ) 14 15 func buildFunction(ctx *cli.Context) error { 16 if !dreamLib.IsRunning() { 17 dreamI18n.Help().IsDreamlandRunning() 18 return dreamI18n.ErrorDreamlandNotStarted 19 } 20 21 function, err := functionPrompts.GetOrSelect(ctx) 22 if err != nil { 23 return err 24 } 25 26 builder, err := initBuild() 27 if err != nil { 28 return err 29 } 30 31 compileFor := &dreamLib.CompileForDFunc{ 32 ProjectId: builder.project.Get().Id(), 33 ResourceId: function.Id, 34 Branch: builder.currentBranch, 35 Call: function.Call, 36 } 37 38 if len(builder.selectedApp) > 0 { 39 app, err := applicationLib.Get(builder.selectedApp) 40 if err != nil { 41 return err 42 } 43 44 compileFor.ApplicationId = app.Id 45 compileFor.Path = path.Join(builder.projectConfig.CodeLoc(), commonSpec.ApplicationPathVariable.String(), builder.selectedApp, functionSpec.PathVariable.String(), function.Name) 46 } else { 47 compileFor.Path = path.Join(builder.projectConfig.CodeLoc(), functionSpec.PathVariable.String(), function.Name) 48 } 49 50 return compileFor.Execute() 51 }