-
Notifications
You must be signed in to change notification settings - Fork 21
/
init.go
49 lines (42 loc) · 964 Bytes
/
init.go
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
// Copyright 2022 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package command
import (
"fmt"
"os/exec"
"strings"
"github.com/vmware-tanzu/tanzu-cli/cmd/plugin/builder/template"
"github.com/vmware-tanzu/tanzu-plugin-runtime/log"
)
const (
github = "github"
)
func Initialize(name, repoType string, dryRun bool) error {
data := struct {
RepositoryName string
}{
RepositoryName: name,
}
targets := template.DefaultInitTargets
if strings.EqualFold(repoType, github) {
targets = append(targets, template.GitHubCI)
} else {
targets = append(targets, template.GitLabCI)
}
for _, target := range targets {
err := target.Run(name, data, dryRun)
if err != nil {
return err
}
}
if dryRun {
return nil
}
c := exec.Command("git", "init", name)
b, err := c.CombinedOutput()
if err != nil {
return fmt.Errorf("%s -- %s", err, string(b))
}
log.Success("successfully created repository")
return nil
}