package recipe import ( "path" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/config" "github.com/go-git/go-git/v5" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) var recipeResetCommand = cli.Command{ Name: "reset", Usage: "Remove all unstaged changes from recipe config", Description: "WARNING, this will delete your changes. Be Careful.", Aliases: []string{"rs"}, ArgsUsage: "", Flags: []cli.Flag{ internal.DebugFlag, internal.NoInputFlag, }, Before: internal.SubCommandBefore, BashComplete: autocomplete.RecipeNameComplete, Action: func(c *cli.Context) error { recipeName := c.Args().First() if recipeName != "" { internal.ValidateRecipe(c) } repoPath := path.Join(config.RECIPES_DIR, recipeName) repo, err := git.PlainOpen(repoPath) if err != nil { logrus.Fatal(err) } ref, err := repo.Head() if err != nil { logrus.Fatal(err) } worktree, err := repo.Worktree() if err != nil { logrus.Fatal(err) } opts := &git.ResetOptions{Commit: ref.Hash(), Mode: git.HardReset} if err := worktree.Reset(opts); err != nil { logrus.Fatal(err) } return nil }, }