forked from Azure/draft-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
45 lines (39 loc) · 1.04 KB
/
create.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
package pack
import (
"fmt"
"os"
"path/filepath"
"github.com/Azure/draft/pkg/draft/pack/repo"
)
// CreateFrom scaffolds a directory with the src pack
func CreateFrom(dest, src string, appName string) error {
// first do some validation that we are copying from a valid pack directory
pack, err := FromDir(src)
if err != nil {
return fmt.Errorf("could not load pack: %s\nTry running:\n\t$ draft pack-repo update", err)
}
// Update ChartName if appName is non-empty
if appName != "" {
pack.Chart.Metadata.Name = appName
} else {
cwd, err := os.Getwd()
if err == nil {
pack.Chart.Metadata.Name = filepath.Base(cwd)
}
}
return pack.SaveDir(dest)
}
// Find loops through each pack repo in packsDir to find pack with given name
func Find(packsDir, name string) ([]string, error) {
packs := []string{}
for _, r := range repo.FindRepositories(packsDir) {
pack, err := r.Pack(name)
if err != nil && err != repo.ErrPackNotFoundInRepo {
return packs, err
}
if pack != "" {
packs = append(packs, pack)
}
}
return packs, nil
}