Skip to content

Commit

Permalink
Clone services folder, if none exist in path
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriiklymiuk committed Oct 6, 2022
1 parent edc441a commit ea801d0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
"text/template"

Expand Down Expand Up @@ -42,6 +44,8 @@ func runInit(cmd *cobra.Command, args []string) {
}

CreateDatabaseServices(services.DatabaseServices)
CreateServicesFolders(services.Services)
}

type FilenameForService struct {
Name string
Expand Down Expand Up @@ -85,6 +89,44 @@ Please provide them in corgi-compose.yml file`)
}
}

func CreateServicesFolders(services []utils.Service) {
for _, service := range services {
if service.Path != "" {
_, err := os.Stat(service.Path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
if service.CloneFrom == "" {
fmt.Printf(
"No directory %s, please provide cloneFrom url or create service in the path",
service.CloneFrom,
)
continue
}
pathSlice := strings.Split(service.Path, "/")
pathWithoutLastFolder := strings.Join(pathSlice[:len(pathSlice)-1], "/")
err := os.MkdirAll(pathWithoutLastFolder, os.ModePerm)
if err != nil {
fmt.Println(err)
continue
}

cmd := exec.Command("git", "clone", service.CloneFrom)
cmd.Dir = pathWithoutLastFolder
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
fmt.Printf(`output error: %s, in path %s with git clone %s
`, err, pathWithoutLastFolder, service.CloneFrom)
}
continue
}
fmt.Println(err)
}
}
}
}

func addFileToGitignore(fileToIgnore string) error {
f, err := os.OpenFile(
".gitignore",
Expand Down

0 comments on commit ea801d0

Please sign in to comment.