Skip to content

Commit befa45b

Browse files
author
{cocoide}
committed
Merge branch 'main' of https://github.com/cocoide/commitify into feature/message-select
2 parents 21de458 + ba623c3 commit befa45b

File tree

5 files changed

+552
-7
lines changed

5 files changed

+552
-7
lines changed

cmd/settings.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"github.com/spf13/cobra"
7+
"github.com/spf13/viper"
8+
)
9+
10+
var setAPIKeyCmd = &cobra.Command{
11+
Use: "set-apikey [api_key]",
12+
Short: "API Key settings for ChatGPT",
13+
Args: cobra.ExactArgs(1),
14+
Run: func (cmd *cobra.Command, args [] string) {
15+
apikey := args[0]
16+
viper.Set("chatgpt.api_key", apikey)
17+
if err := viper.WriteConfig(); err != nil {
18+
log.Fatal("An error occurred while writing the configuration file:", err)
19+
}
20+
fmt.Println("ChatGPT API key has been set")
21+
},
22+
}
23+
24+
var showAPIKeyCmd = &cobra.Command{
25+
Use: "show-apikey",
26+
Short: "Display ChatGPT API key",
27+
Run: func (cmd *cobra.Command, args [] string) {
28+
apikey := viper.GetString("chatgpt.api_key")
29+
if apikey == "" {
30+
fmt.Println("API key is not set")
31+
} else {
32+
fmt.Println("ChatGPT APIKey:", apikey)
33+
}
34+
},
35+
}
36+
37+
func init() {
38+
rootCmd.AddCommand(setAPIKeyCmd)
39+
rootCmd.AddCommand(showAPIKeyCmd)
40+
}

config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
chatgpt:
2+
api_key: apikey

go.mod

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,29 @@ require (
88
github.com/joho/godotenv v1.5.1
99
github.com/sashabaranov/go-openai v1.15.1
1010
github.com/spf13/cobra v1.7.0
11+
github.com/spf13/viper v1.16.0
12+
)
13+
14+
require (
15+
github.com/fsnotify/fsnotify v1.6.0 // indirect
16+
github.com/hashicorp/hcl v1.0.0 // indirect
17+
github.com/magiconair/properties v1.8.7 // indirect
18+
github.com/mattn/go-colorable v0.1.13 // indirect
19+
github.com/mitchellh/mapstructure v1.5.0 // indirect
20+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
21+
github.com/spf13/afero v1.9.5 // indirect
22+
github.com/spf13/cast v1.5.1 // indirect
23+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
24+
github.com/subosito/gotenv v1.4.2 // indirect
25+
gopkg.in/ini.v1 v1.67.0 // indirect
26+
gopkg.in/yaml.v3 v3.0.1 // indirect
1127
)
1228

1329
require (
1430
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1531
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
1632
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1733
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
18-
github.com/mattn/go-colorable v0.1.13 // indirect
1934
github.com/mattn/go-isatty v0.0.18 // indirect
2035
github.com/mattn/go-localereader v0.0.1 // indirect
2136
github.com/mattn/go-runewidth v0.0.14 // indirect
@@ -26,7 +41,7 @@ require (
2641
github.com/rivo/uniseg v0.2.0 // indirect
2742
github.com/spf13/pflag v1.0.5 // indirect
2843
golang.org/x/sync v0.1.0 // indirect
29-
golang.org/x/sys v0.6.0 // indirect
44+
golang.org/x/sys v0.8.0 // indirect
3045
golang.org/x/term v0.6.0 // indirect
31-
golang.org/x/text v0.3.8 // indirect
46+
golang.org/x/text v0.9.0 // indirect
3247
)

0 commit comments

Comments
 (0)