/* Copyright © 2022 NAME HERE */ package cmd 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" ) // 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) { dependencies := []dependencies.Dependency{dependencies.Golang{}} for _, dependency := range dependencies { 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 !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.IsValidPathInput() } } 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.IsValidPathInput() } log.Infof("The following command will be executed:\n%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 successfully installed", dependency.GetName()) } }