main.go

 1package main
 2
 3import (
 4	"context"
 5	"os"
 6	"runtime/debug"
 7
 8	"github.com/charmbracelet/fang"
 9	"github.com/spf13/cobra"
10)
11
12var (
13	commitType     string
14	message        string
15	trailers       []string
16	body           string
17	scope          string
18	breakingChange bool
19)
20
21var rootCmd = &cobra.Command{
22	Use:   "formatted-commit",
23	Short: "Create conventionally formatted Git commits",
24	Long: `formatted-commit helps you create well-formatted Git commits that follow
25the Conventional Commits specification with proper subject length validation,
26body wrapping, and trailer formatting.`,
27	RunE: func(cmd *cobra.Command, args []string) error {
28		// TODO: Implement commit formatting logic here
29		// 1. Validate subject length (type(scope): message <= 50 chars)
30		// 2. Format body as Markdown wrapped to 72 columns
31		// 3. Validate and format trailers
32		// 4. Pipe result to `git commit -F -`
33
34		return nil
35	},
36}
37
38func init() {
39	rootCmd.Flags().StringVarP(&commitType, "type", "t", "", "commit type (required)")
40	rootCmd.Flags().StringVarP(&message, "message", "m", "", "commit message (required)")
41	rootCmd.Flags().StringSliceVarP(&trailers, "trailer", "T", []string{}, "trailer in 'Key: value' format (required, repeatable)")
42	rootCmd.Flags().StringVarP(&body, "body", "b", "", "commit body (required)")
43	rootCmd.Flags().StringVarP(&scope, "scope", "s", "", "commit scope (optional)")
44	rootCmd.Flags().BoolVarP(&breakingChange, "breaking", "B", false, "mark as breaking change (optional)")
45
46	rootCmd.MarkFlagRequired("type")
47	rootCmd.MarkFlagRequired("message")
48	rootCmd.MarkFlagRequired("trailer")
49	rootCmd.MarkFlagRequired("body")
50}
51
52func main() {
53	ctx := context.Background()
54
55	var version string
56	if info, ok := debug.ReadBuildInfo(); ok {
57		version = info.Main.Version
58	}
59	if version == "" || version == "(devel)" {
60		version = "dev"
61	}
62
63	if err := fang.Execute(ctx, rootCmd,
64		fang.WithVersion(version),
65		fang.WithoutCompletions(),
66	); err != nil {
67		os.Exit(1)
68	}
69}