gouick/helpers/dependencies/git.go
Matthieu 'JP' DERASSE 3d878c050d
All checks were successful
continuous-integration/drone/push Build is passing
fix(path): Fix package name after git server migration
2022-11-26 22:36:00 +00:00

109 lines
2.5 KiB
Go

package dependencies
import (
"os/exec"
"git.dev.m-and-m.ovh/mderasse/gouick/models"
"github.com/juju/errors"
log "github.com/sirupsen/logrus"
)
// Git represent an empty struct respecting the DependencyInterface.
type Git struct{}
// regroup all git dependencies function
// GetName return the name of the dependency using DependencyName enum.
func (g Git) GetName() models.DependencyName {
return models.DependencyName_GIT
}
// GetMinimumVersion return the minimum version required for that dependency.
func (g Git) GetMinimumVersion() string {
return "0.0.0"
}
// IsInstalled check if the dependency is installed on the system.
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 will search for the binary and return the path if found.
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 will find the current version of the dependency.
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 will compare the current version with the minimum expected version.
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 define if the dependency installation is handled by the app.
func (g Git) CanBeInstalled() bool {
return false
}
// DescribeInstall will do nothing for that dependency.
func (g Git) DescribeInstall(path string) string {
return ""
}
// Install will do nothing for that dependency.
func (g Git) Install(path string) error {
return nil
}
// DescribePostInstall will do nothing for that dependency.
func (g Git) DescribePostInstall(path string) string {
return ""
}
// PostInstall will do nothing for that dependency.
func (g Git) PostInstall(path string) error {
return nil
}
// GetInstallDirectory will do nothing for that dependency.
func (g Git) GetInstallDirectory() (string, error) {
return "", nil
}