Skip to content

Commit df539bd

Browse files
authored
Merge pull request #102 from GauravJangra9988/os-credentials
Secure API storage
2 parents f688503 + 9d457df commit df539bd

File tree

8 files changed

+238
-114
lines changed

8 files changed

+238
-114
lines changed

cmd/cli/createMsg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323
// CreateCommitMsg launches the interactive flow for reviewing, regenerating,
2424
// editing, and accepting AI-generated commit messages in the current repo.
2525
// If dryRun is true, it displays the prompt without making an API call.
26-
func CreateCommitMsg(dryRun bool, autoCommit bool) {
26+
func CreateCommitMsg(Store *store.StoreMethods, dryRun bool, autoCommit bool) {
2727
// Validate COMMIT_LLM and required API keys
28-
useLLM, err := store.DefaultLLMKey()
28+
useLLM, err := Store.DefaultLLMKey()
2929
if err != nil {
3030
pterm.Error.Printf("No LLM configured. Run: commit llm setup\n")
3131
os.Exit(1)

cmd/cli/llmSetup.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"github.com/manifoldco/promptui"
1010
)
1111

12+
13+
1214
// SetupLLM walks the user through selecting an LLM provider and storing the
1315
// corresponding API key or endpoint configuration.
14-
func SetupLLM() error {
16+
func SetupLLM(Store *store.StoreMethods) error {
1517

1618
providers := types.GetSupportedProviderStrings()
1719
prompt := promptui.Select{
@@ -60,7 +62,7 @@ func SetupLLM() error {
6062
APIKey: apiKey,
6163
}
6264

63-
err = store.Save(LLMConfig)
65+
err = Store.Save(LLMConfig)
6466
if err != nil {
6567
return err
6668
}
@@ -71,7 +73,7 @@ func SetupLLM() error {
7173

7274
// UpdateLLM lets the user switch defaults, rotate API keys, or delete stored
7375
// LLM provider configurations.
74-
func UpdateLLM() error {
76+
func UpdateLLM(Store *store.StoreMethods) error {
7577

7678
SavedModels, err := store.ListSavedModels()
7779
if err != nil {
@@ -88,7 +90,7 @@ func UpdateLLM() error {
8890
options2 := []string{"Set Default", "Change URL", "Delete"} //different option for local model
8991

9092
for _, p := range SavedModels.LLMProviders {
91-
models = append(models, p.LLM.String())
93+
models = append(models, p.String())
9294
}
9395

9496
prompt := promptui.Select{
@@ -146,7 +148,7 @@ func UpdateLLM() error {
146148
if !valid {
147149
return fmt.Errorf("invalid LLM provider: %s", model)
148150
}
149-
err = store.UpdateAPIKey(modelProvider, apiKey)
151+
err = Store.UpdateAPIKey(modelProvider, apiKey)
150152
if err != nil {
151153
return err
152154
}
@@ -160,7 +162,7 @@ func UpdateLLM() error {
160162
if !valid {
161163
return fmt.Errorf("invalid LLM provider: %s", model)
162164
}
163-
err := store.DeleteModel(modelProvider)
165+
err := Store.DeleteModel(modelProvider)
164166
if err != nil {
165167
return err
166168
}

cmd/cli/root.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ package cmd
66
import (
77
"os"
88

9+
"github.com/dfanso/commit-msg/cmd/cli/store"
910
"github.com/spf13/cobra"
1011
)
1112

13+
//store instance
14+
var Store *store.StoreMethods
15+
16+
//Initailize store
17+
func StoreInit(sm *store.StoreMethods){
18+
Store = sm
19+
}
20+
1221
// rootCmd represents the base command when called without any subcommands
1322
var rootCmd = &cobra.Command{
1423
Use: "commit",
@@ -47,15 +56,15 @@ var llmSetupCmd = &cobra.Command{
4756
Use: "setup",
4857
Short: "Setup your LLM provider and API key",
4958
RunE: func(cmd *cobra.Command, args []string) error {
50-
return SetupLLM()
59+
return SetupLLM(Store)
5160
},
5261
}
5362

5463
var llmUpdateCmd = &cobra.Command{
5564
Use: "update",
5665
Short: "Update or Delete LLM Model",
5766
RunE: func(cmd *cobra.Command, args []string) error {
58-
return UpdateLLM()
67+
return UpdateLLM(Store)
5968
},
6069
}
6170

@@ -72,7 +81,7 @@ var creatCommitMsg = &cobra.Command{
7281
if err != nil {
7382
return err
7483
}
75-
CreateCommitMsg(dryRun, autoCommit)
84+
CreateCommitMsg(Store, dryRun, autoCommit)
7685
return nil
7786
},
7887
}
@@ -86,6 +95,7 @@ func init() {
8695

8796
// Cobra also supports local flags, which will only run
8897
// when this action is called directly.
98+
8999
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
90100

91101
// Add --dry-run and --auto as persistent flags so they show in top-level help

0 commit comments

Comments
 (0)