gouick/helpers/dependencies/git.go

110 lines
1.8 KiB
Go
Raw Normal View History

package dependencies
import (
"os/exec"
"github.com/juju/errors"
log "github.com/sirupsen/logrus"
)
type Git struct{}
// regroup all git dependencies function
// GetName
func (g Git) GetName() string {
return "Git"
}
// GetMinimumVersion
func (g Git) GetMinimumVersion() string {
return "0.0.0"
}
// IsInstalled
func (g Git) IsInstalled() (bool, error) {
_, err := g.GetBinaryPath()
if err != nil && !errors.Is(err, exec.ErrNotFound) {
return false, errors.Trace(err)
} else if err != nil && errors.Is(err, exec.ErrNotFound) {
return false, nil
}
return true, nil
}
// GetBinaryPath
func (g Git) GetBinaryPath() (string, error) {
log.Debug("looking for git binary")
path, err := exec.LookPath("git")
if err != nil {
return "", errors.Trace(err)
}
log.Debug("found git binary in", path)
return path, nil
}
// GetVersion
func (g Git) GetVersion() (string, error) {
isInstalled, err := g.IsInstalled()
if err != nil {
return "", errors.Trace(err)
}
if !isInstalled {
return "", errors.NotFoundf("git is not installed on the system")
}
return "0.0.0", nil
}
// IsVersionSupported
func (g Git) IsVersionSupported() (bool, error) {
isInstalled, err := g.IsInstalled()
if err != nil {
return false, errors.Trace(err)
}
if !isInstalled {
return false, nil
}
return true, nil
}
// CanBeInstalled
func (g Git) CanBeInstalled() bool {
return false
}
// DescribeInstall
func (g Git) DescribeInstall(path string) string {
return ""
}
// Install
func (g Git) Install(path string) error {
return nil
}
// DescribePostInstall
func (g Git) DescribePostInstall(path string) string {
return ""
}
// PostInstall
func (g Git) PostInstall(path string) error {
return nil
}
// GetInstallDirectory
func (g Git) GetInstallDirectory() (string, error) {
return "", nil
}