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
62
63
64
65
66
67
68
69
70
71
72
|
diff --git a/registry/registry.go b/registry/registry.go
index 9303e0255de3aa49bab47456f9a25fe6cd1cb3d8..f685756b969d2c7da935d730511c3e3488c20a19 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -48,8 +48,8 @@ }
return nil, ErrTemplateNotFound{Name: name}
}
-// AddTemplate downloads and adds a new Template to the Registry
-func (r *Registry) AddTemplate(name, repo, branch string) (*Template, error) {
+// DownloadTemplate downloads and adds a new Template to the Registry
+func (r *Registry) DownloadTemplate(name, repo, branch string) (*Template, error) {
t := &Template{
reg: r,
Name: name,
@@ -60,6 +60,23 @@ }
r.Templates = append(r.Templates, t)
if err := download(repo, branch, t.ArchivePath()); err != nil {
+ return nil, err
+ }
+
+ return t, r.save()
+}
+
+// SaveTemplate saves a local Template to the Registry
+func (r *Registry) SaveTemplate(name, path string) (*Template, error) {
+ t := &Template{
+ reg: r,
+ Name: name,
+ Path: path,
+ Created: time.Now(),
+ }
+ r.Templates = append(r.Templates, t)
+
+ if err := save(path, t.ArchivePath()); err != nil {
return nil, err
}
@@ -178,11 +195,21 @@ if err := os.RemoveAll(filepath.Join(tmp, ".git")); err != nil {
return err
}
+ // Save the template
+ if err := save(tmp, dest); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func save(source, dest string) error {
+
// Make sure it's a valid template
- if _, err := os.Lstat(filepath.Join(tmp, "template.toml")); err != nil {
+ if _, err := os.Lstat(filepath.Join(source, "template.toml")); err != nil {
return err
}
- fi, err := os.Lstat(filepath.Join(tmp, "template"))
+ fi, err := os.Lstat(filepath.Join(source, "template"))
if err != nil {
return err
}
@@ -191,7 +218,7 @@ return errors.New("template found, expected directory")
}
// Create archive
- glob, err := filepath.Glob(filepath.Join(tmp, "*"))
+ glob, err := filepath.Glob(filepath.Join(source, "*"))
if err != nil {
return err
}
|