feat(dependency): Add git andd handle dependency th cannot be installed by the app
This commit is contained in:
parent
7c9cc568ab
commit
ce433832f7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
@ -7,6 +7,7 @@ package cmd
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.home.m-and-m.ovh/mderasse/boot/helpers/dependencies"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -14,6 +15,11 @@ import (
|
||||
|
||||
var verbose = false
|
||||
var acceptAll = false
|
||||
var dependencyList = []dependencies.Dependency{
|
||||
dependencies.Git{},
|
||||
dependencies.Golang{},
|
||||
dependencies.Swagger{},
|
||||
}
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
|
||||
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
||||
|
||||
*/
|
||||
package cmd
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"git.home.m-and-m.ovh/mderasse/boot/helpers"
|
||||
"git.home.m-and-m.ovh/mderasse/boot/helpers/dependencies"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -31,12 +30,9 @@ func init() {
|
||||
|
||||
func runUpgradeAction(cmd *cobra.Command, args []string) {
|
||||
|
||||
dependencies := []dependencies.Dependency{
|
||||
dependencies.Golang{},
|
||||
dependencies.Swagger{},
|
||||
}
|
||||
log.Debug("Starting Upgrade command")
|
||||
|
||||
for _, dependency := range dependencies {
|
||||
for _, dependency := range dependencyList {
|
||||
|
||||
log.Debugf("Checking if dependency %s is supported", dependency.GetName())
|
||||
|
||||
@ -53,6 +49,11 @@ func runUpgradeAction(cmd *cobra.Command, args []string) {
|
||||
|
||||
log.Infof("Your %s is not supported.", dependency.GetName())
|
||||
|
||||
if !dependency.CanBeInstalled() {
|
||||
log.Warnf("%s cannot be installed by Goguik. Please install it by yourself !", dependency.GetName())
|
||||
continue
|
||||
}
|
||||
|
||||
if !acceptAll {
|
||||
log.Infof("Do you want to install the following version: %s", dependency.GetMinimumVersion())
|
||||
|
||||
|
109
helpers/dependencies/git.go
Normal file
109
helpers/dependencies/git.go
Normal 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
|
||||
}
|
@ -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 {
|
||||
|
||||
|
@ -2,6 +2,7 @@ package dependencies
|
||||
|
||||
// Dependency
|
||||
type Dependency interface {
|
||||
CanBeInstalled() bool
|
||||
DescribeInstall(path string) string
|
||||
DescribePostInstall(path string) string
|
||||
GetBinaryPath() (string, error)
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
package helpers
|
Loading…
x
Reference in New Issue
Block a user