// DoSelfUpdate checks for updates and prompts the user to update if there is a newer version available
DoSelfUpdate checks for updates and prompts the user to update if there is a newer version available
// DoSelfUpdate checks for updates and prompts the user to update if there is a newer version available
func DoSelfUpdate(f *factory.Factory) (bool, error) {
	version := build.Version
	slug := build.RepositoryOwner + "/" + build.RepositoryName
	v := semver.MustParse(version)
	versionToUpdate, found, err := selfupdate.DefaultUpdater().DetectLatest(slug)
	if err != nil {
		return false, err
	}
	if found && versionToUpdate.Version.Equals(v) {
		f.Logger.Debug("Current binary is the latest version", version)
		return false, nil
	}
	promptConfirmName := &survey.Confirm{
		Message: f.Localizer.MustLocalize("common.selfupdate.confirm", localize.NewEntry("Version", versionToUpdate.Version.String())),
	}
	var confirmUpdate bool
	err = survey.AskOne(promptConfirmName, &confirmUpdate)
	if err != nil {
		return false, err
	}
	if !confirmUpdate {
		return false, nil
	}
	latest, err := selfupdate.UpdateSelf(v, slug)
	if err != nil {
		return false, err
	}
	f.Logger.Info(f.Localizer.MustLocalize("common.selfupdate.success", localize.NewEntry("Version", latest.Version)))
	return true, err
}
func DoSelfUpdate ( f * factory . Factory ) ( bool , error ) { version := build . Version slug := build . RepositoryOwner + " " + build . RepositoryName v := semver . MustParse ( version ) versionToUpdate , found , err := selfupdate . DefaultUpdater ( ) . DetectLatest ( slug ) if err != nil { return false , err } if found && versionToUpdate . Version . Equals ( v ) { f . Logger . Debug ( " " , version ) return false , nil } promptConfirmName := & survey . Confirm { Message : f . Localizer . MustLocalize ( " " , localize . NewEntry ( " " , versionToUpdate . Version . String ( ) ) ) , } var confirmUpdate bool err = survey . AskOne ( promptConfirmName , & confirmUpdate ) if err != nil { return false , err } if ! confirmUpdate { return false , nil } latest , err := selfupdate . UpdateSelf ( v , slug ) if err != nil { return false , err } f . Logger . Info ( f . Localizer . MustLocalize ( " " , localize . NewEntry ( " " , latest . Version ) ) ) return true , err }
DoSelfUpdate checks for updates and prompts the user to update if there is a newer version available
DoSelfUpdate checks for updates and prompts the user to update if there is a newer version available
// latest version is the same as current version. It means current binary is up to date.