package recipe

import (
	"strings"

	"coopcloud.tech/abra/cli/internal"
	"coopcloud.tech/abra/pkg/autocomplete"
	gitPkg "coopcloud.tech/abra/pkg/git"
	"coopcloud.tech/abra/pkg/i18n"
	"coopcloud.tech/abra/pkg/log"
	"github.com/spf13/cobra"
)

// translators: `abra recipe diff` aliases. use a comma separated list of aliases
// with no spaces in between
var recipeDiffAliases = i18n.G("d")

var RecipeDiffCommand = &cobra.Command{
	// translators: `recipe diff` command
	Use:     i18n.G("diff <recipe> [flags]"),
	Aliases: strings.Split(recipeDiffAliases, ","),
	// translators: Short description for `recipe diff` command
	Short: i18n.G("Show unstaged changes in recipe config"),
	Long:  i18n.G("This command requires /usr/bin/git."),
	Args:  cobra.MinimumNArgs(1),
	ValidArgsFunction: func(
		cmd *cobra.Command,
		args []string,
		toComplete string) ([]string, cobra.ShellCompDirective) {
		return autocomplete.RecipeNameComplete()
	},
	Run: func(cmd *cobra.Command, args []string) {
		r := internal.ValidateRecipe(args, cmd.Name())
		if err := gitPkg.DiffUnstaged(r.Dir); err != nil {
			log.Fatal(err)
		}
	},
}
