forked from toolshed/abra
refactor!: cobra migrate
This commit is contained in:
@ -2,7 +2,6 @@ package recipe
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -20,7 +19,7 @@ import (
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type imgPin struct {
|
||||
@ -37,12 +36,11 @@ type anUpgrade struct {
|
||||
UpgradeTags []string `json:"upgrades"`
|
||||
}
|
||||
|
||||
var recipeUpgradeCommand = cli.Command{
|
||||
Name: "upgrade",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Upgrade recipe image tags",
|
||||
UsageText: "abra recipe upgrade [<recipe>] [options]",
|
||||
Description: `Upgrade a given <recipe> configuration.
|
||||
var RecipeUpgradeCommand = &cobra.Command{
|
||||
Use: "upgrade <recipe> [flags]",
|
||||
Aliases: []string{"u"},
|
||||
Short: "Upgrade recipe image tags",
|
||||
Long: `Upgrade a given <recipe> configuration.
|
||||
|
||||
It will update the relevant compose file tags on the local file system.
|
||||
|
||||
@ -55,18 +53,15 @@ make a seclection. Use the "?" key to see more help on navigating this
|
||||
interface.
|
||||
|
||||
You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
Flags: []cli.Flag{
|
||||
internal.PatchFlag,
|
||||
internal.MinorFlag,
|
||||
internal.MajorFlag,
|
||||
internal.MachineReadableFlag,
|
||||
internal.AllTagsFlag,
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
args []string,
|
||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return autocomplete.RecipeNameComplete()
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
ShellComplete: autocomplete.RecipeNameComplete,
|
||||
HideHelp: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
recipe := internal.ValidateRecipe(cmd)
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
recipe := internal.ValidateRecipe(args, cmd.Name())
|
||||
|
||||
if err := recipe.Ensure(internal.Chaos, internal.Offline); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -177,7 +172,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
|
||||
sort.Sort(tagcmp.ByTagDesc(compatible))
|
||||
|
||||
if len(compatible) == 0 && !internal.AllTags {
|
||||
if len(compatible) == 0 && !allTags {
|
||||
log.Info(fmt.Sprintf("no new versions available for %s, assuming %s is the latest (use -a/--all-tags to see all anyway)", image, tag))
|
||||
continue // skip on to the next tag and don't update any compose files
|
||||
}
|
||||
@ -231,7 +226,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
for _, upTag := range compatible {
|
||||
upElement, err := tag.UpgradeDelta(upTag)
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
delta := upElement.UpgradeType()
|
||||
if delta <= bumpType {
|
||||
@ -245,9 +240,9 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
} else {
|
||||
msg := fmt.Sprintf("upgrade to which tag? (service: %s, image: %s, tag: %s)", service.Name, image, tag)
|
||||
if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) || internal.AllTags {
|
||||
if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) || allTags {
|
||||
tag := img.(reference.NamedTagged).Tag()
|
||||
if !internal.AllTags {
|
||||
if !allTags {
|
||||
log.Warn(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)
|
||||
@ -315,7 +310,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
|
||||
fmt.Println(string(jsonstring))
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
for _, upgrade := range upgradeList {
|
||||
@ -336,7 +331,51 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var (
|
||||
allTags bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Major,
|
||||
"major",
|
||||
"x",
|
||||
false,
|
||||
"increase the major part of the version",
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Minor,
|
||||
"minor",
|
||||
"y",
|
||||
false,
|
||||
"increase the minor part of the version",
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Patch,
|
||||
"patch",
|
||||
"z",
|
||||
false,
|
||||
"increase the patch part of the version",
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.MachineReadable,
|
||||
"machine",
|
||||
"m",
|
||||
false,
|
||||
"print machine-readable output",
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&allTags,
|
||||
"all-tags",
|
||||
"a",
|
||||
false,
|
||||
"list all tags, not just upgrades",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user