package recipe import ( "fmt" "os/exec" "path" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/config" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) // getGitDiffArgs builds the `git diff` invocation args func getGitDiffArgs(repoPath string) []string { return []string{ "-C", repoPath, "--no-pager", "-c", "color.diff=always", "diff", } } var recipeDiffCommand = cli.Command{ Name: "diff", Usage: "Show unstaged changes in recipe config", Description: "Due to limitations in our underlying Git dependency, this command requires /usr/bin/git.", Aliases: []string{"d"}, 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) } _, err := exec.LookPath("git") if err != nil { logrus.Fatal("unable to locate 'git' command?") } gitDiffArgs := getGitDiffArgs(path.Join(config.RECIPES_DIR, recipeName)) diff, err := exec.Command("git", gitDiffArgs...).Output() if err != nil { logrus.Fatal(err) } fmt.Print(string(diff)) return nil }, }