Add machine output for recipe/upgrade
- Normal faff related to calling external libraries with structs thnx go - Ouputs json now
This commit is contained in:
parent
34b274bc52
commit
152c5d4563
@ -2,6 +2,7 @@ package recipe
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
@ -27,11 +28,11 @@ type imgPin struct {
|
||||
version tagcmp.Tag
|
||||
}
|
||||
|
||||
type upgradeList struct {
|
||||
service string
|
||||
image string
|
||||
tag string
|
||||
upgradeTags []string
|
||||
type anUpgrade struct {
|
||||
Service string `json:"service"`
|
||||
Image string `json:"image"`
|
||||
Tag string `json:"tag"`
|
||||
UpgradeTags []string `json:"upgrades"`
|
||||
}
|
||||
|
||||
var recipeUpgradeCommand = cli.Command{
|
||||
@ -63,6 +64,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
internal.PatchFlag,
|
||||
internal.MinorFlag,
|
||||
internal.MajorFlag,
|
||||
internal.MachineReadableFlag,
|
||||
internal.AllTagsFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
@ -82,7 +84,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
}
|
||||
}
|
||||
|
||||
var upgrades []upgradeList
|
||||
upgradeList := make(map[string]anUpgrade)
|
||||
|
||||
// check for versions file and load pinned versions
|
||||
versionsPresent := false
|
||||
@ -250,21 +252,21 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
}
|
||||
}
|
||||
|
||||
upgrade := upgradeList{
|
||||
service: service.Name,
|
||||
image: image,
|
||||
tag: tag.String(),
|
||||
upgradeTags: make([]string, len(compatibleStrings[1:])),
|
||||
upgrade := anUpgrade{
|
||||
Service: service.Name,
|
||||
Image: image,
|
||||
Tag: tag.String(),
|
||||
UpgradeTags: make([]string, len(compatibleStrings[1:])),
|
||||
}
|
||||
|
||||
for n, s := range compatibleStrings[1:] {
|
||||
var sb strings.Builder
|
||||
if _, err := sb.WriteString(s); err != nil {
|
||||
}
|
||||
upgrade.upgradeTags[n] = sb.String()
|
||||
upgrade.UpgradeTags[n] = sb.String()
|
||||
}
|
||||
|
||||
upgrades = append(upgrades, upgrade)
|
||||
upgradeList[upgrade.Service] = upgrade
|
||||
|
||||
if internal.NoInput {
|
||||
upgradeTag = "skip"
|
||||
@ -297,11 +299,20 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
||||
}
|
||||
|
||||
if internal.NoInput {
|
||||
// FIXME handle machine-readable here
|
||||
for _, upgrade := range upgrades {
|
||||
logrus.Infof("can upgrade service: %s, image: %s, tag: %s ::\n", upgrade.service, upgrade.image, upgrade.tag)
|
||||
for _, utag := range upgrade.upgradeTags {
|
||||
logrus.Infof(" %s\n", utag)
|
||||
if internal.MachineReadable {
|
||||
jsonstring, err := json.Marshal(upgradeList)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
} else {
|
||||
fmt.Println(string(jsonstring))
|
||||
}
|
||||
|
||||
} else {
|
||||
for _, upgrade := range upgradeList {
|
||||
logrus.Infof("can upgrade service: %s, image: %s, tag: %s ::\n", upgrade.Service, upgrade.Image, upgrade.Tag)
|
||||
for _, utag := range upgrade.UpgradeTags {
|
||||
logrus.Infof(" %s\n", utag)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user