@@ -4,31 +4,77 @@ import (
44 "encoding/json"
55 "fmt"
66
7+ pb "github.com/cocoide/commitify/pkg/grpc"
78 "github.com/spf13/viper"
89)
910
11+ type Language int
12+
13+ const (
14+ JP Language = iota
15+ EN
16+ )
17+
18+ type CodeFormat int
19+
20+ const (
21+ EmojiFormat CodeFormat = iota
22+ PrefixFormat
23+ NormalFormat
24+ )
25+
26+ type AISource int
27+
28+ const (
29+ WrapServer AISource = iota
30+ OpenAiAPI
31+ )
32+
1033type Config struct {
11- ChatGptApiKey string `json:"chatGptApiKey"`
12- UseLanguage string `json:"UseLanguage"`
13- CommitFormat string `json:"CommitFormat"`
34+ ChatGptApiKey string `json:"chatGpt_ApiKey"`
35+ UseLanguage int `json:"Use_Language"`
36+ CommitFormat int `json:"Commit_Format"`
37+ AISource int `json:"AI_Source"`
38+ }
39+
40+ func (c * Config ) Config2PbVars () (pb.CodeFormatType , pb.LanguageType ) {
41+ var codeFormatType pb.CodeFormatType
42+ switch c .CommitFormat {
43+ case int (EmojiFormat ):
44+ codeFormatType = pb .CodeFormatType_EMOJI
45+ case int (PrefixFormat ):
46+ codeFormatType = pb .CodeFormatType_PREFIX
47+ default :
48+ codeFormatType = pb .CodeFormatType_NORMAL
49+ }
50+
51+ var languageType pb.LanguageType
52+ switch c .UseLanguage {
53+ case int (JP ):
54+ languageType = pb .LanguageType_JAPANESE
55+ default :
56+ languageType = pb .LanguageType_JAPANESE
57+ }
58+
59+ return codeFormatType , languageType
1460}
1561
16- func ReadConfig () (* Config , error ) {
62+ func ReadConfig () (Config , error ) {
1763 var result Config
1864
1965 viper .AddConfigPath ("." )
2066 viper .SetConfigName ("config" )
2167 viper .SetConfigType ("yaml" )
2268 if err := viper .ReadInConfig (); err != nil {
23- return & result , fmt .Errorf ("error reading config file, %s" , err .Error ())
69+ return result , fmt .Errorf ("error reading config file, %s" , err .Error ())
2470 }
2571 if err := viper .Unmarshal (& result ); err != nil {
26- return & result , fmt .Errorf ("unable to decode into struct, %v" , err .Error ())
72+ return result , fmt .Errorf ("unable to decode into struct, %v" , err .Error ())
2773 }
28- return & result , nil
74+ return result , nil
2975}
3076
31- func WriteConfig (config * Config ) error {
77+ func WriteConfig (config Config ) error {
3278 viper .AddConfigPath ("." )
3379 viper .SetConfigName ("config" )
3480 viper .SetConfigType ("yaml" )
0 commit comments