Sagi Dayan
29e31c5b21
All checks were successful
CI / check for spelling errors (pull_request) Successful in 21s
CI / code quality (lint/tests) (pull_request) Successful in 2m6s
CI / make sure build does not fail (pull_request) Successful in 2m22s
CI / notify-fail (pull_request) Has been skipped
CI / check for spelling errors (push) Successful in 21s
CI / code quality (lint/tests) (push) Successful in 2m4s
CI / make sure build does not fail (push) Successful in 2m24s
CI / notify-fail (push) Has been skipped
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
81 lines
2 KiB
Go
81 lines
2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.dayanhub.com/sagi/envoid/internal/datastore"
|
|
"git.dayanhub.com/sagi/envoid/internal/prompt"
|
|
"git.dayanhub.com/sagi/envoid/internal/variables"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var initCmd = &cobra.Command{
|
|
Use: "init",
|
|
Short: "creates a new project for this path. default env is set to `local`",
|
|
Long: "",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
_, err := configuration.GetProject(workingDir)
|
|
if err == nil {
|
|
fmt.Printf("Project already exists. please remove if you wish to override\n")
|
|
|
|
return nil
|
|
}
|
|
ds, err := datastore.NewDataStore()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer ds.Close()
|
|
|
|
var name string
|
|
var pass string
|
|
var envNames []string
|
|
|
|
// check if we are importing an existing file
|
|
if ds.DoesFileExists() {
|
|
fmt.Printf("Project was not found locally. But found %s file in path.\n", variables.DBFileName)
|
|
fmt.Printf("Importing Project for %s\n", workingDir)
|
|
|
|
name = prompt.StringPrompt("Project Name:")
|
|
pass = prompt.PasswordPrompt("Project Password (Same password that was used originally):")
|
|
|
|
envNames, err = ds.ListEnvironments()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("Found %d environments. importing %v\n", len(envNames), envNames)
|
|
|
|
} else {
|
|
// New Project
|
|
fmt.Printf("Creating new Project @ %s\n", workingDir)
|
|
name = prompt.StringPrompt("Project Name:")
|
|
pass = prompt.PasswordPrompt("Project Password:")
|
|
envs := strings.TrimSpace(prompt.StringPrompt("Please provide environment names separated by `,`. (stage,prod):"))
|
|
if len(envs) == 0 {
|
|
envs = "local"
|
|
}
|
|
envNames = strings.Split(envs, ",")
|
|
}
|
|
|
|
project, err = configuration.NewProject(name, workingDir, pass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, eName := range envNames {
|
|
if err := project.NewEnv(eName); err != nil {
|
|
return err
|
|
}
|
|
if err := ds.CreateEnv(eName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
configuration.Save()
|
|
fmt.Println("✅ Done")
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
}
|