2022-07-15 11:49:53 +00:00
|
|
|
/*
|
2022-07-16 15:46:09 +00:00
|
|
|
Copyright © 2022 Matthieu Derasse <git@derasse.fr>
|
2022-07-15 11:49:53 +00:00
|
|
|
*/
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2022-11-26 22:36:00 +00:00
|
|
|
"git.dev.m-and-m.ovh/mderasse/gouick/helpers"
|
|
|
|
"git.dev.m-and-m.ovh/mderasse/gouick/helpers/input"
|
2022-07-15 11:49:53 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-08-03 11:17:15 +00:00
|
|
|
// upgradeCmd represents the upgrade command.
|
2022-07-15 11:49:53 +00:00
|
|
|
var upgradeCmd = &cobra.Command{
|
|
|
|
Use: "upgrade",
|
|
|
|
Short: "Upgrade all development dependencies",
|
|
|
|
Long: `Upgrade the following dependencies:
|
|
|
|
- Golang
|
|
|
|
- Go Swagger
|
|
|
|
- ...
|
|
|
|
`,
|
|
|
|
Run: runUpgradeAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(upgradeCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runUpgradeAction(cmd *cobra.Command, args []string) {
|
2022-07-16 15:46:09 +00:00
|
|
|
log.Debug("Starting Upgrade command")
|
2022-07-15 11:49:53 +00:00
|
|
|
|
2022-07-16 15:46:09 +00:00
|
|
|
for _, dependency := range dependencyList {
|
2022-07-15 11:49:53 +00:00
|
|
|
log.Debugf("Checking if dependency %s is supported", dependency.GetName())
|
|
|
|
|
|
|
|
isSupported, err := dependency.IsVersionSupported()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Fail to check %s version. The following error happen: %s", dependency.GetName(), err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if isSupported {
|
|
|
|
log.Infof("%s version is supported, continue", dependency.GetName())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("Your %s is not supported.", dependency.GetName())
|
|
|
|
|
2022-07-16 15:46:09 +00:00
|
|
|
if !dependency.CanBeInstalled() {
|
2022-07-25 20:43:53 +00:00
|
|
|
log.Warnf("%s cannot be installed by Gouick. Please install it by yourself !", dependency.GetName())
|
2022-07-16 15:46:09 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-15 11:49:53 +00:00
|
|
|
if !acceptAll {
|
|
|
|
log.Infof("Do you want to install the following version: %s", dependency.GetMinimumVersion())
|
|
|
|
|
2022-09-16 20:22:19 +00:00
|
|
|
answer := input.YesOrNo()
|
2022-07-15 11:49:53 +00:00
|
|
|
if !answer {
|
|
|
|
log.Warnf("Skipping installation of %s. Some part of the application might not be able to work correctly!", dependency.GetName())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Trying to find the best installation directory")
|
|
|
|
|
|
|
|
installDirectory, err := dependency.GetInstallDirectory()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Fail to compute the %s install directory. The following error happen: %s", dependency.GetName(), err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// ask user if the path is correct, else ask new path and check validity
|
|
|
|
if !acceptAll {
|
|
|
|
log.Infof("Do you want to install %s in the directory %s ?", dependency.GetName(), installDirectory)
|
|
|
|
|
2022-09-16 20:22:19 +00:00
|
|
|
answer := input.YesOrNo()
|
2022-07-15 11:49:53 +00:00
|
|
|
if !answer {
|
|
|
|
log.Infof("Where do you want to install %s ?", dependency.GetName())
|
2022-09-16 20:22:19 +00:00
|
|
|
installDirectory = input.Path(true)
|
2022-07-15 11:49:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Infof("Installing %s in the following directory: %s", dependency.GetName(), installDirectory)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Checking directory and creating it if needed")
|
|
|
|
|
|
|
|
// check if the path is ok, else ask user for new path if we are in a interactive mode, else stop
|
2022-08-02 20:30:46 +00:00
|
|
|
_, err = helpers.CheckAndCreateDir(installDirectory)
|
2022-07-15 11:49:53 +00:00
|
|
|
if err != nil {
|
2022-08-03 11:17:15 +00:00
|
|
|
log.Errorf("Impossible to create the installation directory for %s", dependency.GetName())
|
2022-07-15 11:49:53 +00:00
|
|
|
if acceptAll {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Infof("Where do you want to install %s ?", dependency.GetName())
|
2022-09-16 20:22:19 +00:00
|
|
|
installDirectory = input.Path(true)
|
2022-07-15 11:49:53 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 22:16:59 +00:00
|
|
|
log.Infof("%s", dependency.DescribeInstall(installDirectory))
|
2022-07-15 11:49:53 +00:00
|
|
|
log.Info("Do you want to continue ?")
|
2022-09-16 20:22:19 +00:00
|
|
|
answer := input.YesOrNo()
|
2022-07-15 11:49:53 +00:00
|
|
|
if !answer {
|
|
|
|
log.Warnf("Skipping installation of %s. Some part of the application might not be able to work correctly!", dependency.GetName())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Starting the installation")
|
|
|
|
|
|
|
|
err = dependency.Install(installDirectory)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Fail to install %s version. The following error happen: %s", dependency.GetName(), err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-15 22:16:59 +00:00
|
|
|
log.Infof("%s", dependency.DescribePostInstall(installDirectory))
|
|
|
|
log.Info("Do you want to continue ?")
|
2022-09-16 20:22:19 +00:00
|
|
|
answer = input.YesOrNo()
|
2022-07-15 22:16:59 +00:00
|
|
|
if !answer {
|
|
|
|
log.Warnf("Skipping post installation of %s. Some part of the application might not be able to work correctly!", dependency.GetName())
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Launching post install")
|
|
|
|
err = dependency.PostInstall(installDirectory)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Fail to execute post install of %s. The following error happen: %s", dependency.GetName(), err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-15 11:49:53 +00:00
|
|
|
log.Infof("%s successfully installed", dependency.GetName())
|
|
|
|
}
|
|
|
|
}
|