This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathegpt.go
86 lines (75 loc) · 2.48 KB
/
egpt.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// This file is part of the e.GPT distribution.
// Copyright (c) Next.e.GO Mobile SE, Aachen, Germany (https://e-go-mobile.com/)
//
// e-gpt is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, version 3.
//
// e-gpt is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
egoCommands "github.com/egomobile/e-gpt/commands"
egoUICommand "github.com/egomobile/e-gpt/commands/ui"
egoUtils "github.com/egomobile/e-gpt/utils"
)
var rootCmd = &cobra.Command{
Use: "egpt",
Short: `e.GPT is a command line tool running with ChatGPT.`,
Long: `e.GPT is a command line tool running with ChatGPT.`,
Version: AppVersion,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
func initCommands() {
egoCommands.Init_ask_Command(rootCmd)
egoCommands.Init_code_Command(rootCmd)
egoCommands.Init_describe_Command(rootCmd)
egoCommands.Init_environment_Command(rootCmd)
egoCommands.Init_explain_Command(rootCmd)
egoCommands.Init_fix_Command(rootCmd)
egoCommands.Init_optimize_Command(rootCmd)
egoCommands.Init_shell_Command(rootCmd)
egoCommands.Init_sql_Command(rootCmd)
egoCommands.Init_summarize_Command(rootCmd)
egoCommands.Init_translate_Command(rootCmd)
egoUICommand.Init_ui_Command(rootCmd)
}
func main() {
// try to load .env file from
// ${HOME}/.egpt
egptEnv, err := egoUtils.GetEnvFilePath()
if err != nil {
log.Println("[WARN]", fmt.Sprintf("Could not detect home directory: %v", err.Error()))
} else {
if _, err := os.Stat(egptEnv); err == nil {
err := godotenv.Load(egptEnv)
if err != nil {
log.Fatalf("Error loading .egpt/.env file: %v", err.Error())
}
}
}
// try to load .env from current working directory
if _, err := os.Stat(".env"); err == nil {
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Error loading .env file: %v", err.Error())
}
}
initCommands()
err = rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}