2023-01-22 19:53:25 +00:00
|
|
|
package recipe
|
|
|
|
|
|
|
|
import (
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
|
|
"coopcloud.tech/abra/pkg/recipe"
|
2023-02-14 23:49:22 +00:00
|
|
|
"coopcloud.tech/abra/pkg/runtime"
|
2023-01-22 19:53:25 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var recipeFetchCommand = cli.Command{
|
|
|
|
Name: "fetch",
|
|
|
|
Usage: "Fetch recipe local copies",
|
|
|
|
Aliases: []string{"f"},
|
|
|
|
ArgsUsage: "[<recipe>]",
|
|
|
|
Description: "Fetchs all recipes without arguments.",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
internal.DebugFlag,
|
2023-07-26 06:16:07 +00:00
|
|
|
internal.OfflineFlag,
|
2023-01-22 19:53:25 +00:00
|
|
|
},
|
|
|
|
Before: internal.SubCommandBefore,
|
|
|
|
BashComplete: autocomplete.RecipeNameComplete,
|
|
|
|
Action: func(c *cli.Context) error {
|
2023-07-26 06:16:07 +00:00
|
|
|
conf := runtime.New(runtime.WithOffline(internal.Offline))
|
2023-01-22 19:53:25 +00:00
|
|
|
recipeName := c.Args().First()
|
2023-02-14 23:49:22 +00:00
|
|
|
|
2023-01-22 19:53:25 +00:00
|
|
|
if recipeName != "" {
|
2023-07-26 06:16:07 +00:00
|
|
|
internal.ValidateRecipe(c, conf)
|
2023-01-22 19:53:25 +00:00
|
|
|
return nil // ValidateRecipe ensures latest checkout
|
|
|
|
}
|
|
|
|
|
2023-07-26 06:16:07 +00:00
|
|
|
repos, err := recipe.ReadReposMetadata(conf)
|
2023-01-22 19:53:25 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-02-14 23:49:22 +00:00
|
|
|
if err := recipe.UpdateRepositories(repos, recipeName, conf); err != nil {
|
2023-01-22 19:53:25 +00:00
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|