src.dualinventive.com/go/devsim/repository/git/template.go

71 lines
1.5 KiB
Go

package git
import (
"os"
"time"
"gopkg.in/src-d/go-git.v4/plumbing"
"src.dualinventive.com/go/devsim/repository"
)
// Template contains all the data that a particular simulator needs in order to run.
type Template struct {
author string
authorEmail string
key plumbing.Hash
name string
time time.Time
tagHash *plumbing.Hash
manager *manager
}
// Static check
var _ repository.Template = &Template{}
// Create ensures that all the data is available.
func (g *Template) Create() error {
return g.manager.clone(g.key)
}
// Destroy removes all the template data.
func (g *Template) Destroy() error {
return os.RemoveAll(g.Path())
}
// Path returns the location where the template files are located
func (g *Template) Path() string {
return g.manager.hashPath(g.key)
}
// Name returns the name of the template.
func (g *Template) Name() string {
return g.manager.uri
}
// Key returns the commit hash of the template.
func (g *Template) Key() string {
return g.key.String()
}
// Version is the semantic version of the template
func (g *Template) Version() string {
if g.tagHash == nil {
return g.Key()
}
version, err := g.manager.versionByTagHash(*g.tagHash)
if err != nil {
return g.Key()
}
return version
}
// Author is the e-mail address of the author who created the template.
func (g *Template) Author() string {
return g.authorEmail
}
// DeviceUID gets the deviceuid
func (g *Template) DeviceUID() string {
return ""
}