forked from DFanso/commit-msg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
149 lines (124 loc) · 3.91 KB
/
root.go
File metadata and controls
149 lines (124 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package cmd
import (
"os"
"github.com/dfanso/commit-msg/cmd/cli/store"
"github.com/spf13/cobra"
)
// store instance
var Store *store.StoreMethods
// Initailize store
func StoreInit(sm *store.StoreMethods) {
Store = sm
}
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "commit",
Short: "CLI tool to write commit message",
Long: `Write a commit message with AI of your choice`,
Example: `
# Generate a commit message and run the interactive review flow
commit .
# Preview what would be sent to the LLM without making an API call
commit . --dry-run
# Generate a commit message and automatically commit it
commit . --auto
# Show verbose debug information (diff stats, full prompts, repository details)
commit . --toggle
commit . --dry-run --toggle
`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
var llmCmd = &cobra.Command{
Use: "llm",
Short: "Manage LLM configuration",
}
var llmSetupCmd = &cobra.Command{
Use: "setup",
Short: "Setup your LLM provider and API key",
RunE: func(cmd *cobra.Command, args []string) error {
return SetupLLM(Store)
},
}
var llmUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update or Delete LLM Model",
RunE: func(cmd *cobra.Command, args []string) error {
return UpdateLLM(Store)
},
}
var cacheCmd = &cobra.Command{
Use: "cache",
Short: "Manage commit message cache",
Long: `Manage the cache of generated commit messages to reduce API costs and improve performance.`,
}
var cacheStatsCmd = &cobra.Command{
Use: "stats",
Short: "Show cache statistics",
RunE: func(cmd *cobra.Command, args []string) error {
return ShowCacheStats(Store)
},
}
var cacheClearCmd = &cobra.Command{
Use: "clear",
Short: "Clear all cached messages",
RunE: func(cmd *cobra.Command, args []string) error {
return ClearCache(Store)
},
}
var cacheCleanupCmd = &cobra.Command{
Use: "cleanup",
Short: "Remove old cached messages",
RunE: func(cmd *cobra.Command, args []string) error {
return CleanupCache(Store)
},
}
var creatCommitMsg = &cobra.Command{
Use: ".",
Short: "Create Commit Message",
RunE: func(cmd *cobra.Command, args []string) error {
dryRun, err := cmd.Flags().GetBool("dry-run")
if err != nil {
return err
}
autoCommit, err := cmd.Flags().GetBool("auto")
if err != nil {
return err
}
verbose, err := cmd.Flags().GetBool("toggle")
if err != nil {
return err
}
CreateCommitMsg(Store, dryRun, autoCommit, verbose)
return nil
},
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.commit-msg.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
// Add --dry-run, --auto, and --toggle as persistent flags so they show in top-level help
rootCmd.PersistentFlags().Bool("dry-run", false, "Preview the prompt that would be sent to the LLM without making an API call")
rootCmd.PersistentFlags().Bool("auto", false, "Automatically commit with the generated message")
rootCmd.PersistentFlags().BoolP("toggle", "t", false, "Show verbose debug information (diff stats, full prompts, repository details)")
rootCmd.AddCommand(creatCommitMsg)
rootCmd.AddCommand(llmCmd)
rootCmd.AddCommand(cacheCmd)
llmCmd.AddCommand(llmSetupCmd)
llmCmd.AddCommand(llmUpdateCmd)
cacheCmd.AddCommand(cacheStatsCmd)
cacheCmd.AddCommand(cacheClearCmd)
cacheCmd.AddCommand(cacheCleanupCmd)
}