forked from toolshed/abra
refactor!: cobra migrate
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@ -13,34 +12,38 @@ import (
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var recipeSyncCommand = cli.Command{
|
||||
Name: "sync",
|
||||
Aliases: []string{"s"},
|
||||
Usage: "Sync recipe version label",
|
||||
UsageText: "abra recipe lint <recipe> [<version>] [options]",
|
||||
Flags: []cli.Flag{
|
||||
internal.DryFlag,
|
||||
internal.MajorFlag,
|
||||
internal.MinorFlag,
|
||||
internal.PatchFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `Generate labels for the main recipe service.
|
||||
var RecipeSyncCommand = &cobra.Command{
|
||||
Use: "sync <recipe> [version] [flags]",
|
||||
Aliases: []string{"s"},
|
||||
Short: "Sync recipe version label",
|
||||
Long: `Generate labels for the main recipe service.
|
||||
|
||||
By convention, the service named "app" using the following format:
|
||||
|
||||
coop-cloud.${STACK_NAME}.version=<version>
|
||||
|
||||
Where <version> can be specifed on the command-line or Abra can attempt to
|
||||
Where [version] can be specifed on the command-line or Abra can attempt to
|
||||
auto-generate it for you. The <recipe> configuration will be updated on the
|
||||
local file system.`,
|
||||
ShellComplete: autocomplete.RecipeNameComplete,
|
||||
HideHelp: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
recipe := internal.ValidateRecipe(cmd)
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
args []string,
|
||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
switch l := len(args); l {
|
||||
case 0:
|
||||
return autocomplete.RecipeNameComplete()
|
||||
case 1:
|
||||
return autocomplete.RecipeVersionComplete(args[0])
|
||||
default:
|
||||
return nil, cobra.ShellCompDirectiveError
|
||||
}
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
recipe := internal.ValidateRecipe(args, cmd.Name())
|
||||
|
||||
mainApp, err := internal.GetMainAppImage(recipe)
|
||||
if err != nil {
|
||||
@ -59,7 +62,11 @@ local file system.`,
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
nextTag := cmd.Args().Get(1)
|
||||
var nextTag string
|
||||
if len(args) == 2 {
|
||||
nextTag = args[1]
|
||||
}
|
||||
|
||||
if len(tags) == 0 && nextTag == "" {
|
||||
log.Warnf("no git tags found for %s", recipe.Name)
|
||||
if internal.NoInput {
|
||||
@ -205,7 +212,39 @@ likely to change.
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RecipeSyncCommand.Flags().BoolVarP(
|
||||
&internal.Dry,
|
||||
"dry-run",
|
||||
"r",
|
||||
false,
|
||||
"report changes that would be made",
|
||||
)
|
||||
|
||||
RecipeSyncCommand.Flags().BoolVarP(
|
||||
&internal.Major,
|
||||
"major",
|
||||
"x",
|
||||
false,
|
||||
"increase the major part of the version",
|
||||
)
|
||||
|
||||
RecipeSyncCommand.Flags().BoolVarP(
|
||||
&internal.Minor,
|
||||
"minor",
|
||||
"y",
|
||||
false,
|
||||
"increase the minor part of the version",
|
||||
)
|
||||
|
||||
RecipeSyncCommand.Flags().BoolVarP(
|
||||
&internal.Patch,
|
||||
"patch",
|
||||
"z",
|
||||
false,
|
||||
"increase the patch part of the version",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user