forked from toolshed/abra
refactor!: cobra migrate
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package catalogue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -16,41 +15,42 @@ import (
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var catalogueGenerateCommand = cli.Command{
|
||||
Name: "generate",
|
||||
Aliases: []string{"g"},
|
||||
Usage: "Generate the recipe catalogue",
|
||||
UsageText: "abra catalogue generate [<recipe>] [options]",
|
||||
Flags: []cli.Flag{
|
||||
internal.PublishFlag,
|
||||
internal.DryFlag,
|
||||
internal.SkipUpdatesFlag,
|
||||
internal.ChaosFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `Generate a new copy of the recipe catalogue.
|
||||
var CatalogueGenerateCommand = &cobra.Command{
|
||||
Use: "generate [recipe] [flags]",
|
||||
Aliases: []string{"g"},
|
||||
Short: "Generate the recipe catalogue",
|
||||
Long: `Generate a new copy of the recipe catalogue.
|
||||
|
||||
It is possible to generate new metadata for a single recipe by passing
|
||||
<recipe>. The existing local catalogue will be updated, not overwritten.
|
||||
[recipe]. The existing local catalogue will be updated, not overwritten.
|
||||
|
||||
It is quite easy to get rate limited by Docker Hub when running this command.
|
||||
If you have a Hub account you can have Abra log you in to avoid this. Pass
|
||||
"--user" and "--pass".
|
||||
|
||||
Push your new release to git.coopcloud.tech with "-p/--publish". This requires
|
||||
Push your new release to git.coopcloud.tech with "--publish/-p". This requires
|
||||
that you have permission to git push to these repositories and have your SSH
|
||||
keys configured on your account.`,
|
||||
ShellComplete: autocomplete.RecipeNameComplete,
|
||||
HideHelp: true,
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
recipeName := cmd.Args().First()
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
args []string,
|
||||
toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
return autocomplete.RecipeNameComplete()
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var recipeName string
|
||||
if len(args) > 0 {
|
||||
recipeName = args[0]
|
||||
}
|
||||
|
||||
r := recipe.Get(recipeName)
|
||||
|
||||
if recipeName != "" {
|
||||
internal.ValidateRecipe(cmd)
|
||||
internal.ValidateRecipe(args, cmd.Name())
|
||||
}
|
||||
|
||||
if !internal.Chaos {
|
||||
@ -74,7 +74,7 @@ keys configured on your account.`,
|
||||
logMsg = fmt.Sprintf("ensuring %v recipes are cloned & up-to-date, this could take some time...", barLength)
|
||||
}
|
||||
|
||||
if !internal.SkipUpdates {
|
||||
if !skipUpdates {
|
||||
log.Warn(logMsg)
|
||||
if err := recipe.UpdateRepositories(repos, recipeName); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -145,7 +145,7 @@ keys configured on your account.`,
|
||||
log.Infof("generated new recipe catalogue in %s", config.RECIPES_JSON)
|
||||
|
||||
cataloguePath := path.Join(config.ABRA_DIR, "catalogue")
|
||||
if internal.Publish {
|
||||
if publishChanges {
|
||||
|
||||
isClean, err := gitPkg.IsClean(cataloguePath)
|
||||
if err != nil {
|
||||
@ -188,7 +188,7 @@ keys configured on your account.`,
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !internal.Dry && internal.Publish {
|
||||
if !internal.Dry && publishChanges {
|
||||
url := fmt.Sprintf("%s/%s/commit/%s", config.REPOS_BASE_URL, config.CATALOGUE_JSON_REPO_NAME, head.Hash())
|
||||
log.Infof("new changes published: %s", url)
|
||||
}
|
||||
@ -196,18 +196,51 @@ keys configured on your account.`,
|
||||
if internal.Dry {
|
||||
log.Info("dry run: no changes published")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// CatalogueCommand defines the `abra catalogue` command and sub-commands.
|
||||
var CatalogueCommand = cli.Command{
|
||||
Name: "catalogue",
|
||||
Usage: "Manage the recipe catalogue",
|
||||
Aliases: []string{"c"},
|
||||
UsageText: "abra catalogue [command] [options] [arguments]",
|
||||
Commands: []*cli.Command{
|
||||
&catalogueGenerateCommand,
|
||||
},
|
||||
var CatalogueCommand = &cobra.Command{
|
||||
Use: "catalogue [cmd] [args] [flags]",
|
||||
Short: "Manage the recipe catalogue",
|
||||
Aliases: []string{"c"},
|
||||
}
|
||||
|
||||
var (
|
||||
publishChanges bool
|
||||
skipUpdates bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
CatalogueGenerateCommand.Flags().BoolVarP(
|
||||
&publishChanges,
|
||||
"publish",
|
||||
"p",
|
||||
false,
|
||||
"publish changes to git.coopcloud.tech",
|
||||
)
|
||||
|
||||
CatalogueGenerateCommand.Flags().BoolVarP(
|
||||
&internal.Dry,
|
||||
"dry-run",
|
||||
"r",
|
||||
false,
|
||||
"report changes that would be made",
|
||||
)
|
||||
|
||||
CatalogueGenerateCommand.Flags().BoolVarP(
|
||||
&skipUpdates,
|
||||
"skip-updates",
|
||||
"s",
|
||||
false,
|
||||
"skip updating recipe repositories",
|
||||
)
|
||||
|
||||
CatalogueGenerateCommand.Flags().BoolVarP(
|
||||
&internal.Chaos,
|
||||
"chaos",
|
||||
"C",
|
||||
false,
|
||||
"ignore uncommitted recipes changes",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user