-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
hepler.go
69 lines (53 loc) · 1.59 KB
/
hepler.go
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
package cmd
import (
"errors"
"fmt"
"github.com/appleboy/CodeGPT/openai"
"github.com/appleboy/CodeGPT/prompt"
"github.com/appleboy/CodeGPT/util"
"github.com/appleboy/com/file"
"github.com/spf13/viper"
)
func check() error {
// Check if the Git command is available on the system's PATH
if !util.IsCommandAvailable("git") {
return errors.New("Git command not found on your system's PATH. Please install Git and try again.")
}
// Update Viper configuration values based on the CLI flags
if diffUnified != 3 {
viper.Set("git.diff_unified", diffUnified)
}
if len(excludeList) > 0 {
viper.Set("git.exclude_list", excludeList)
}
if prompt.GetLanguage(commitLang) != prompt.DefaultLanguage {
viper.Set("output.lang", commitLang)
}
if openai.GetModel(commitModel) != openai.DefaultModel {
viper.Set("openai.model", commitModel)
}
if httpsProxy != "" {
viper.Set("openai.proxy", httpsProxy)
}
if socksProxy != "" {
viper.Set("openai.socks", socksProxy)
}
if maxTokens != 300 {
viper.Set("openai.max_tokens", maxTokens)
}
if templateFile != "" {
viper.Set("git.template_file", templateFile)
}
if templateString != "" {
viper.Set("git.template_string", templateString)
}
// Check if the template file specified in the configuration exists
templateFile := viper.GetString("git.template_file")
if templateFile != "" && !file.IsFile(templateFile) {
return fmt.Errorf("template file not found: %s", templateFile)
}
if templateVarsFile != "" && !file.IsFile(templateVarsFile) {
return fmt.Errorf("template variables file not found: %s", templateVarsFile)
}
return nil
}