-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (37 loc) · 795 Bytes
/
main.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
package main
import (
"fmt"
"github.com/vonhraban/shai/internal/openai_client"
"os"
"strings"
)
var config *Config
func init() {
config = initConfig()
}
func main() {
input := getInputFromArgs(os.Args)
for input == "" {
input = askPrompt("")
}
if input == "setup" {
fmt.Println("Setup wizard")
return
}
var client openai_client.Client
if !config.DummyAPI {
client = openai_client.NewChatGPTClient(config.APIHost, config.APIKey)
} else {
client = &openai_client.DummyClient{}
}
client.SetDebug(config.DebugMode)
command := promptForInputInteractive(client, input)
if command == "" {
exitWithMessage("Cancelled")
}
printMessagef("Executing")
executeCommand(command)
}
func getInputFromArgs(args []string) string {
return strings.Join(args[1:], " ")
}