github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/lib/project/push_config.go (about) 1 //go:build !localAuthClient 2 3 package projectLib 4 5 import ( 6 "os" 7 "path" 8 "strings" 9 10 "github.com/taubyte/go-project-schema/project" 11 "github.com/taubyte/tau-cli/singletons/config" 12 httpClient "github.com/taubyte/tau/clients/http/auth" 13 ) 14 15 func cloneProjectAndPushConfig(clientProject *httpClient.Project, location, description, user string, embedToken bool) error { 16 // Build location to clone the project, either to cwd/<project name> or providedLoc/<project name> 17 if len(location) == 0 { 18 cwd, err := os.Getwd() 19 if err != nil { 20 return err 21 } 22 location = path.Join(cwd, clientProject.Name) 23 24 // Check if user has already defined project name in given location 25 } else if !strings.HasSuffix(strings.ToLower(location), strings.ToLower(clientProject.Name)) { 26 location = path.Join(location, clientProject.Name) 27 } 28 29 // Set new project in config ~/tau.yaml 30 configProject := config.Project{ 31 DefaultProfile: user, 32 Location: location, 33 } 34 err := config.Projects().Set(clientProject.Name, configProject) 35 if err != nil { 36 return err 37 } 38 39 // Clone project to given location 40 projectRepository, err := Repository(clientProject.Name).Clone(configProject, embedToken) 41 if err != nil { 42 return err 43 } 44 45 // Get go-project-schema project for config access 46 projectIface, err := SelectedProjectInterface() 47 if err != nil { 48 return err 49 } 50 51 // Get GitEmail from profile 52 profile, err := config.Profiles().Get(user) 53 if err != nil { 54 return err 55 } 56 57 err = projectIface.Set(true, 58 project.Id(clientProject.Id), 59 project.Name(clientProject.Name), 60 project.Description(description), 61 project.Email(profile.GitEmail), 62 ) 63 if err != nil { 64 return err 65 } 66 67 // Get the config repository commit and push 68 gitRepo, err := projectRepository.Config() 69 if err != nil { 70 return err 71 } 72 73 err = gitRepo.Commit("init", ".") 74 if err != nil { 75 return err 76 } 77 78 return gitRepo.Push() 79 }