diff --git a/cmd/generate.go b/cmd/generate.go index 8dbbc5f..28985dc 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateAPI.go b/cmd/generateAPI.go index 9d8d2d2..4551262 100644 --- a/cmd/generateAPI.go +++ b/cmd/generateAPI.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateDB.go b/cmd/generateDB.go index 7bf1a00..ec24d05 100644 --- a/cmd/generateDB.go +++ b/cmd/generateDB.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateDocker.go b/cmd/generateDocker.go index 14cffd1..5f6dc01 100644 --- a/cmd/generateDocker.go +++ b/cmd/generateDocker.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateHelm.go b/cmd/generateHelm.go index 4586c57..bcd10ec 100644 --- a/cmd/generateHelm.go +++ b/cmd/generateHelm.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateHelp.go b/cmd/generateHelp.go index 75b7933..141f97b 100644 --- a/cmd/generateHelp.go +++ b/cmd/generateHelp.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateLauncher.go b/cmd/generateLauncher.go index 98db40c..471ddaf 100644 --- a/cmd/generateLauncher.go +++ b/cmd/generateLauncher.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/generateMakefile.go b/cmd/generateMakefile.go index 39ed8fb..bccfb1a 100644 --- a/cmd/generateMakefile.go +++ b/cmd/generateMakefile.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/init.go b/cmd/init.go index 059a543..9b5ed6c 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/root.go b/cmd/root.go index fcbe7a6..15303d8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ 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{ diff --git a/cmd/test.go b/cmd/test.go index 4ddc231..c86ab8d 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package cmd diff --git a/cmd/upgrade.go b/cmd/upgrade.go index 2d715fd..63eb2b7 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ 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()) diff --git a/helpers/dependencies/git.go b/helpers/dependencies/git.go new file mode 100644 index 0000000..033bb7c --- /dev/null +++ b/helpers/dependencies/git.go @@ -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 +} diff --git a/helpers/dependencies/golang.go b/helpers/dependencies/golang.go index beb56d9..d6bde77 100644 --- a/helpers/dependencies/golang.go +++ b/helpers/dependencies/golang.go @@ -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 { diff --git a/helpers/dependencies/interface.go b/helpers/dependencies/interface.go index c43c8cd..0e8d7ab 100644 --- a/helpers/dependencies/interface.go +++ b/helpers/dependencies/interface.go @@ -2,6 +2,7 @@ package dependencies // Dependency type Dependency interface { + CanBeInstalled() bool DescribeInstall(path string) string DescribePostInstall(path string) string GetBinaryPath() (string, error) diff --git a/helpers/dependencies/swagger.go b/helpers/dependencies/swagger.go index ff51e51..09294fe 100644 --- a/helpers/dependencies/swagger.go +++ b/helpers/dependencies/swagger.go @@ -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 { diff --git a/helpers/http.go b/helpers/http.go deleted file mode 100644 index 345b806..0000000 --- a/helpers/http.go +++ /dev/null @@ -1 +0,0 @@ -package helpers diff --git a/main.go b/main.go index 5005149..a8e1251 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* -Copyright © 2022 NAME HERE +Copyright © 2022 Matthieu Derasse */ package main