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 Example: `
28# With co-author
29formatted-commit -t feat -m "do a thing" -T "Crush <crush@charm.land>"
30
31# Breaking change with longer body
32formatted-commit -t feat -m "do a thing that borks a thing" -B "$(cat <<'EOF'
33Multi-line
34- Body
35- Here
36
37This is what borked because of new shiny, this is how migrate
38EOF
39)"
40
41# Including scope for more precise changes
42formatted-commit -t refactor -s "web/git-bug" -m "fancy shmancy" \
43 -b "Had to do a weird thing because..."
44`,
45 RunE: func(cmd *cobra.Command, args []string) error {
46 // TODO: Implement commit formatting logic here
47 // 1. Validate subject length (type(scope): message <= 50 chars)
48 // 2. Format body as Markdown wrapped to 72 columns
49 // 3. Validate and format trailers
50 // 4. Pipe result to `git commit -F -`
51
52 return nil
53 },
54}
55
56func init() {
57 rootCmd.Flags().StringVarP(&commitType, "type", "t", "", "commit type (required)")
58 rootCmd.Flags().StringVarP(&message, "message", "m", "", "commit message (required)")
59 rootCmd.Flags().StringSliceVarP(&trailers, "trailer", "T", []string{}, "trailer in 'Sentence-case-key: value' format (optional, repeatable)")
60 rootCmd.Flags().StringVarP(&body, "body", "b", "", "commit body (optional)")
61 rootCmd.Flags().StringVarP(&scope, "scope", "s", "", "commit scope (optional)")
62 rootCmd.Flags().BoolVarP(&breakingChange, "breaking", "B", false, "mark as breaking change (optional)")
63
64 if err := rootCmd.MarkFlagRequired("type"); err != nil {
65 panic(err)
66 }
67 if err := rootCmd.MarkFlagRequired("message"); err != nil {
68 panic(err)
69 }
70}
71
72func main() {
73 ctx := context.Background()
74
75 var version string
76 if info, ok := debug.ReadBuildInfo(); ok {
77 version = info.Main.Version
78 }
79 if version == "" || version == "(devel)" {
80 version = "dev"
81 }
82
83 if err := fang.Execute(ctx, rootCmd,
84 fang.WithVersion(version),
85 fang.WithoutCompletions(),
86 ); err != nil {
87 os.Exit(1)
88 }
89}