Skip to content

Commit 3f6b9a4

Browse files
committed
feat(cmd): add cost command for expense analysis
- Introduce `cost` command to display the cost of commit messages. - Implement `runCost` function to retrieve and display expenses using `utils` and `ui` packages. - Handle errors for missing or failed expense retrieval. [Generated by Kommit]
1 parent 050ddd0 commit 3f6b9a4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

cmd/cost.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"os"
7+
8+
"github.com/cowboy-bebug/kommit/internal/ui"
9+
"github.com/cowboy-bebug/kommit/internal/utils"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var costCmd = &cobra.Command{
14+
Use: "cost",
15+
Short: "Show the cost of your commitment therapy",
16+
Long: `💰 Kommit Cost Analysis - Because emotional growth has a price tag!
17+
18+
This command reveals how much your repository's therapy sessions have cost you so far.
19+
Think of it as reviewing your therapy bills - a necessary part of the healing process.
20+
21+
Just as real therapy isn't free, AI-powered commit messages come with a cost.
22+
Still, it's cheaper than the emotional damage of trying to decipher "fixed stuff"
23+
six months from now when you're debugging at 3 AM.
24+
25+
Your wallet might need its own support group, but your future self will thank you
26+
for the investment in clear, meaningful commit history.`,
27+
Run: runCost,
28+
}
29+
30+
func runCost(cmd *cobra.Command, args []string) {
31+
costs, err := utils.GetCosts()
32+
if err != nil {
33+
if errors.Is(err, utils.CostFileNotFoundError{}) {
34+
fmt.Println("😰 Financial abandonment detected: It hasn't committed any expenses yet.")
35+
fmt.Println("(Have you run `git kommit` yet?)")
36+
os.Exit(0)
37+
}
38+
fmt.Println("😰 Financial abandonment detected: Failed to retrieve your expenses.")
39+
os.Exit(1)
40+
}
41+
42+
if err = ui.CostTableModel(costs); err != nil {
43+
ui.HandleQuitError(err)
44+
if err != nil {
45+
fmt.Println("😰 Financial abandonment detected: Failed to display your expenses.")
46+
os.Exit(1)
47+
}
48+
}
49+
50+
}
51+
52+
func init() {
53+
rootCmd.AddCommand(costCmd)
54+
}

0 commit comments

Comments
 (0)