feat(dependency): Add git andd handle dependency th cannot be installed by the app

This commit is contained in:
Matthieu 'JP' DERASSE
2022-07-16 15:46:09 +00:00
parent 7c9cc568ab
commit ce433832f7
18 changed files with 148 additions and 22 deletions

109
helpers/dependencies/git.go Normal file
View File

@ -0,0 +1,109 @@
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
}

View File

@ -128,13 +128,18 @@ func (g Golang) IsVersionSupported() (bool, error) {
return false, errors.Trace(err)
}
if installedVersion.LT(*&requiredVersion) {
if installedVersion.LT(requiredVersion) {
return false, nil
}
return true, nil
}
// CanBeInstalled
func (g Golang) CanBeInstalled() bool {
return true
}
// DescribeInstall
func (g Golang) DescribeInstall(path string) string {

View File

@ -2,6 +2,7 @@ package dependencies
// Dependency
type Dependency interface {
CanBeInstalled() bool
DescribeInstall(path string) string
DescribePostInstall(path string) string
GetBinaryPath() (string, error)

View File

@ -127,13 +127,18 @@ func (s Swagger) IsVersionSupported() (bool, error) {
return false, errors.Trace(err)
}
if installedVersion.LT(*&requiredVersion) {
if installedVersion.LT(requiredVersion) {
return false, nil
}
return true, nil
}
// CanBeInstalled
func (s Swagger) CanBeInstalled() bool {
return true
}
// DescribeInstall
func (s Swagger) DescribeInstall(path string) string {

View File

@ -1 +0,0 @@
package helpers