@@ -6,9 +6,10 @@ import (
6
6
7
7
"github.com/charmbracelet/bubbles/textinput"
8
8
tea "github.com/charmbracelet/bubbletea"
9
- "github.com/cocoide/commitify/internal/entity"
10
9
"github.com/fatih/color"
11
10
"github.com/spf13/cobra"
11
+
12
+ "github.com/cocoide/commitify/internal/entity"
12
13
)
13
14
14
15
var (
@@ -27,29 +28,29 @@ var (
27
28
}
28
29
)
29
30
30
- type configModel struct {
31
+ type configCmdModel struct {
31
32
configKeyIndex int
32
33
configOptionIndex int
33
34
configKeySelected bool
34
35
err error
35
36
textInput textinput.Model
36
37
}
37
38
38
- func initConfigModel () configModel {
39
+ func initConfigModel () configCmdModel {
39
40
ti := textinput .New ()
40
41
ti .Focus ()
41
42
42
- return configModel {
43
+ return configCmdModel {
43
44
textInput : ti ,
44
45
err : nil ,
45
46
}
46
47
}
47
48
48
- func (cm configModel ) Init () tea.Cmd {
49
+ func (cm configCmdModel ) Init () tea.Cmd {
49
50
return textinput .Blink
50
51
}
51
52
52
- func (cm configModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
53
+ func (cm configCmdModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
53
54
switch cm .configKeySelected {
54
55
// 設定項目を選択する
55
56
case false :
@@ -82,7 +83,7 @@ func (cm configModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
82
83
case tea.KeyMsg :
83
84
switch msg .Type {
84
85
case tea .KeyEnter :
85
- saveConfig (cm )
86
+ entity . SaveConfig (cm . configKeyIndex , - 1 , cm . textInput . Value () )
86
87
return cm , tea .Quit
87
88
case tea .KeyCtrlC , tea .KeyEsc :
88
89
return cm , tea .Quit
@@ -109,7 +110,7 @@ func (cm configModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
109
110
cm .configOptionIndex ++
110
111
}
111
112
case tea .KeyEnter :
112
- saveConfig (cm )
113
+ entity . SaveConfig (cm . configKeyIndex , configOption [cm. configKeyIndex ][cm. configOptionIndex ], "" )
113
114
return cm , tea .Quit
114
115
case tea .KeyCtrlC , tea .KeyEsc :
115
116
return cm , tea .Quit
@@ -121,7 +122,7 @@ func (cm configModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
121
122
return cm , nil
122
123
}
123
124
124
- func (cm configModel ) View () string {
125
+ func (cm configCmdModel ) View () string {
125
126
var b strings.Builder
126
127
127
128
switch cm .configKeySelected {
@@ -180,26 +181,3 @@ var configCmd = &cobra.Command{
180
181
func init () {
181
182
rootCmd .AddCommand (configCmd )
182
183
}
183
-
184
- func saveConfig (cm configModel ) {
185
- currentConfig , err := entity .ReadConfig ()
186
- if err != nil {
187
- fmt .Println (err )
188
- }
189
-
190
- switch cm .configKeyIndex {
191
- case 0 :
192
- currentConfig .ChatGptApiKey = cm .textInput .Value ()
193
- case 1 :
194
- currentConfig .UseLanguage = configOption [cm.configKeyIndex ][cm.configOptionIndex ]
195
- case 2 :
196
- currentConfig .CommitFormat = configOption [cm.configKeyIndex ][cm.configOptionIndex ]
197
- case 3 :
198
- currentConfig .AISource = configOption [cm.configKeyIndex ][cm.configOptionIndex ]
199
- }
200
-
201
- err = entity .WriteConfig (currentConfig )
202
- if err != nil {
203
- fmt .Println (err )
204
- }
205
- }
0 commit comments