diff --git a/registry/error.go b/registry/error.go index d85f168..f7950f4 100644 --- a/registry/error.go +++ b/registry/error.go @@ -2,6 +2,19 @@ package registry import "fmt" +type ErrTemplateExists struct { + Name string +} + +func (e ErrTemplateExists) Error() string { + return fmt.Sprintf("template %s already exists", e.Name) +} + +func IsErrTemplateExists(err error) bool { + _, ok := err.(ErrTemplateExists) + return ok +} + type ErrTemplateNotFound struct { Name string } diff --git a/registry/registry.go b/registry/registry.go index 8fb27b9..d2ddf01 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -50,6 +50,10 @@ func (r *Registry) GetTemplate(name string) (*Template, error) { // DownloadTemplate downloads and adds a new Template to the Registry func (r *Registry) DownloadTemplate(name, repo, branch string) (*Template, error) { + if _, err := r.GetTemplate(name); err == nil { + return nil, ErrTemplateExists{Name: name} + } + t := &Template{ reg: r, Name: name, @@ -68,6 +72,10 @@ func (r *Registry) DownloadTemplate(name, repo, branch string) (*Template, error // SaveTemplate saves a local Template to the Registry func (r *Registry) SaveTemplate(name, path string) (*Template, error) { + if _, err := r.GetTemplate(name); err == nil { + return nil, ErrTemplateExists{Name: name} + } + t := &Template{ reg: r, Name: name,