/* Copyright © 2022 Matthieu Derasse */ package cmd import ( "github.com/spf13/cobra" "git.home.m-and-m.ovh/mderasse/gouick/helpers" log "github.com/sirupsen/logrus" ) // upgradeCmd represents the upgrade command 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) { log.Debug("Starting Upgrade command") for _, dependency := range dependencyList { 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()) if !dependency.CanBeInstalled() { log.Warnf("%s cannot be installed by Gouick. Please install it by yourself !", dependency.GetName()) continue } if !acceptAll { log.Infof("Do you want to install the following version: %s", dependency.GetMinimumVersion()) answer := helpers.YesOrNoInput() 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) answer := helpers.YesOrNoInput() if !answer { log.Infof("Where do you want to install %s ?", dependency.GetName()) installDirectory = helpers.PathInput() } } 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 _, err = helpers.CheckAndCreateDir(installDirectory) if err != nil { log.Errorf("Impossible to create the instalation directory for %s", dependency.GetName()) if acceptAll { return } log.Infof("Where do you want to install %s ?", dependency.GetName()) installDirectory = helpers.PathInput() } log.Infof("%s", dependency.DescribeInstall(installDirectory)) log.Info("Do you want to continue ?") answer := helpers.YesOrNoInput() 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 } log.Infof("%s", dependency.DescribePostInstall(installDirectory)) log.Info("Do you want to continue ?") answer = helpers.YesOrNoInput() 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 } log.Infof("%s successfully installed", dependency.GetName()) } }