-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (88 loc) · 1.75 KB
/
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
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
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"git-client/utils"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: git <command> [args]")
os.Exit(1)
}
command := os.Args[1]
repo, err := utils.NewGitRepo(".")
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
switch command {
case "config":
if len(os.Args) != 4 {
fmt.Println("Usage: git config <username> <email>")
os.Exit(1)
}
username := os.Args[2]
email := os.Args[3]
err := repo.SetConfig(username, email)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Println("Config set successfully:", username, email)
case "init":
err := repo.Init()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Println("Initialized empty repository:", repo.Path)
case "add":
if len(os.Args) != 3 {
fmt.Println("Usage: git add <file>")
os.Exit(1)
}
filePath := os.Args[2]
err := repo.Add(filePath)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Println("Added to index:", filePath)
case "status":
status, err := repo.Status()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Print(status)
case "commit":
if len(os.Args) < 3 {
fmt.Println("Usage: git commit <message>")
os.Exit(1)
}
message := os.Args[2]
commitHash, err := repo.Commit(message)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Println("Committed to master:", commitHash)
case "diff":
diff, err := repo.Diff()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Print(diff)
case "logs":
diff, err := repo.Logs()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
fmt.Print(diff)
default:
fmt.Println("Unknown command:", command)
os.Exit(1)
}
}