package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

var commitMsg string

var commitCmd = &cobra.Command{
	Use:   "commit",
	Short: "Stage all changes and commit",
	RunE: func(cmd *cobra.Command, args []string) error {
		if commitMsg == "" {
			return fmt.Errorf("commit message required — use -m \"your message\"")
		}
		if err := runGit(".", "add", "-A"); err != nil {
			return err
		}
		return runGit(".", "commit", "-m", commitMsg)
	},
}

func init() {
	commitCmd.Flags().StringVarP(&commitMsg, "message", "m", "", "Commit message")
	_ = commitCmd.MarkFlagRequired("message")
}
