-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathcreate.go
More file actions
61 lines (50 loc) · 1.97 KB
/
Copy pathcreate.go
File metadata and controls
61 lines (50 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"fmt"
"path"
"strings"
"github.com/commitdev/zero/internal/config/projectconfig"
"github.com/commitdev/zero/internal/constants"
"github.com/commitdev/zero/internal/generate"
"github.com/commitdev/zero/internal/vcs"
"github.com/commitdev/zero/pkg/util/exit"
"github.com/commitdev/zero/pkg/util/flog"
"github.com/spf13/cobra"
)
var (
createConfigPath string
overwriteFiles bool
)
func init() {
createCmd.PersistentFlags().StringVarP(&createConfigPath, "config", "c", constants.ZeroProjectYml, "The project.yml file to load. The default is the one in the current directory.")
createCmd.PersistentFlags().BoolVarP(&overwriteFiles, "overwrite", "o", false, "overwrite pre-existing files")
rootCmd.AddCommand(createCmd)
}
var createCmd = &cobra.Command{
Use: "create",
Short: fmt.Sprintf("Create projects for modules and configuration specified in %s", constants.ZeroProjectYml),
Run: func(cmd *cobra.Command, args []string) {
Create(projectconfig.RootDir, createConfigPath)
},
}
func Create(dir string, createConfigPath string) {
if strings.Trim(createConfigPath, " ") == "" {
exit.Fatal("config path cannot be empty!")
}
configFilePath := path.Join(dir, createConfigPath)
projectConfig := projectconfig.LoadConfig(configFilePath)
generate.Generate(*projectConfig, overwriteFiles)
if projectConfig.ShouldPushRepositories {
flog.Infof(":up_arrow: Done Rendering - committing repositories to version control.")
for _, module := range projectConfig.Modules {
err, githubApiKey := projectconfig.ReadVendorCredentialsFromModule(module, "github")
if err != nil {
flog.Errorf(err.Error())
}
vcs.InitializeRepository(module.Files.Repository, githubApiKey)
}
} else {
flog.Infof(":up_arrow: Done Rendering - you will need to commit the created projects to version control.")
}
flog.Infof(":check_mark_button: Done - run zero apply to create any required infrastructure or execute any other remote commands to prepare your environments.")
}