github.com/bilus/oya@v0.0.3-0.20190301162104-da4acbd394c6/pkg/pack/pack.go (about) 1 package pack 2 3 import ( 4 "github.com/bilus/oya/pkg/semver" 5 "github.com/bilus/oya/pkg/types" 6 "github.com/pkg/errors" 7 ) 8 9 type Repo interface { 10 Install(version semver.Version, installDir string) error 11 IsInstalled(version semver.Version, installDir string) (bool, error) 12 InstallPath(version semver.Version, installDir string) string 13 ImportPath() types.ImportPath 14 } 15 16 // Pack represents a specific version of an Oya pack. 17 type Pack struct { 18 repo Repo 19 version semver.Version 20 replacementPath string 21 } 22 23 func New(repo Repo, version semver.Version) (Pack, error) { 24 return Pack{ 25 repo: repo, 26 version: version, 27 }, nil 28 } 29 30 func (p Pack) LocalReplacement(replacementPath string) Pack { 31 return Pack{ 32 repo: p.repo, 33 version: p.version, 34 replacementPath: replacementPath, 35 } 36 } 37 38 func (p Pack) ReplacementPath() (string, bool) { 39 return p.replacementPath, len(p.replacementPath) > 0 40 } 41 42 func (p Pack) Install(installDir string) error { 43 // log.Println("Installing", p.ImportPath(), "@", p.Version(), "to", installDir) 44 err := p.repo.Install(p.version, installDir) 45 if err != nil { 46 return errors.Wrapf(err, "error installing pack %v", p.ImportPath()) 47 } 48 return nil 49 } 50 51 func (p Pack) IsInstalled(installDir string) (bool, error) { 52 return p.repo.IsInstalled(p.version, installDir) 53 } 54 55 func (p Pack) Version() semver.Version { 56 return p.version 57 } 58 59 func (p Pack) ImportPath() types.ImportPath { 60 return p.repo.ImportPath() 61 } 62 63 func (p Pack) InstallPath(installDir string) string { 64 return p.repo.InstallPath(p.version, installDir) 65 }