From 6fc5c3134740a38bfe5b512e9b0d53625b03fc31 Mon Sep 17 00:00:00 2001 From: knoflook Date: Fri, 1 Oct 2021 19:48:48 +0200 Subject: [PATCH] WIP: #172 upgrade --major/minor/patch placeholder --- cli/recipe/upgrade.go | 70 +++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/cli/recipe/upgrade.go b/cli/recipe/upgrade.go index 627d46b81..e1884c94a 100644 --- a/cli/recipe/upgrade.go +++ b/cli/recipe/upgrade.go @@ -29,9 +29,22 @@ semver-like convention. In this case, all possible tags will be listed and it is up to the end-user to decide. `, ArgsUsage: "", + Flags: []cli.Flag{ + PatchFlag, + MinorFlag, + MajorFlag, + }, Action: func(c *cli.Context) error { recipe := internal.ValidateRecipe(c) + bumpType := btoi(Major)*4 + btoi(Minor)*2 + btoi(Patch) + if bumpType != 0 { + // a bitwise check if the number is a power of 2 + if (bumpType & (bumpType - 1)) != 0 { + logrus.Fatal("you can only use one of: --major, --minor, --patch.") + } + } + for _, service := range recipe.Config.Services { catlVersions, err := catalogue.VersionsOfService(recipe.Name, service.Name) if err != nil { @@ -104,31 +117,44 @@ is up to the end-user to decide. } logrus.Debugf("detected compatible upgradable tags '%s' for '%s'", compatibleStrings, service.Name) + if bumpType != 0 { + if bumpType == 1 { + // Patch upgrade + fmt.Println("Patch") + } else if bumpType == 2 { + // Minor upgrade + fmt.Println("Minor") + } else { + // Major upgrade + fmt.Println("Major") + } + } else { + msg := fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag) + if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { + tag := img.(reference.NamedTagged).Tag() + logrus.Warning(fmt.Sprintf("unable to determine versioning semantics of '%s', listing all tags", tag)) + msg = fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag) + compatibleStrings = []string{} + for _, regVersion := range regVersions { + compatibleStrings = append(compatibleStrings, regVersion.Name) + } + } - msg := fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag) - if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { - tag := img.(reference.NamedTagged).Tag() - logrus.Warning(fmt.Sprintf("unable to determine versioning semantics of '%s', listing all tags", tag)) - msg = fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag) - compatibleStrings = []string{} - for _, regVersion := range regVersions { - compatibleStrings = append(compatibleStrings, regVersion.Name) + var upgradeTag string + prompt := &survey.Select{ + Message: msg, + Options: compatibleStrings, + } + if err := survey.AskOne(prompt, &upgradeTag); err != nil { + logrus.Fatal(err) } } - - var upgradeTag string - prompt := &survey.Select{ - Message: msg, - Options: compatibleStrings, - } - if err := survey.AskOne(prompt, &upgradeTag); err != nil { - logrus.Fatal(err) - } - - if err := recipe.UpdateTag(image, upgradeTag); err != nil { - logrus.Fatal(err) - } - logrus.Debugf("tag updated from '%s' to '%s' for '%s'", image, upgradeTag, recipe.Name) + /* + if err := recipe.UpdateTag(image, upgradeTag); err != nil { + logrus.Fatal(err) + } + logrus.Debugf("tag updated from '%s' to '%s' for '%s'", image, upgradeTag, recipe.Name) + */ } return nil