-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (73 loc) · 1.71 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
package main
import (
"fmt"
"github.com/learnercys/mini-git/commands"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: mini-git <command> [<args>]")
os.Exit(1)
}
command := os.Args[1]
args := os.Args[2:]
cwd, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current working directory:", err)
os.Exit(1)
}
switch command {
case "init":
if err := commands.Init(cwd); err != nil {
fmt.Println("Error initializing repository:", err)
os.Exit(1)
}
case "add":
if len(args) < 1 {
fmt.Println("Usage: mini-git add <file>")
os.Exit(1)
}
if err := commands.Add(cwd, args[0]); err != nil {
fmt.Println("Error adding file:", err)
os.Exit(1)
}
case "commit":
if len(args) < 1 {
fmt.Println("Usage: mini-git commit <message>")
os.Exit(1)
}
author := "John Doe <[email protected]> " // TODO: get author from config
if err := commands.Commit(cwd, author, args[0]); err != nil {
fmt.Println("Error committing changes:", err)
os.Exit(1)
}
case "log":
if err := commands.Log(cwd); err != nil {
fmt.Println("Error showing commit log:", err)
os.Exit(1)
}
case "status":
if err := commands.Status(cwd); err != nil {
fmt.Println("Error showing status:", err)
os.Exit(1)
}
case "branch":
if err := commands.Branch(cwd, args); err != nil {
fmt.Println("Error managing branches:", err)
os.Exit(1)
}
case "checkout":
if err := commands.Checkout(cwd, args); err != nil {
fmt.Println("Error checking out branch:", err)
os.Exit(1)
}
case "merge":
if err := commands.Merge(cwd, args); err != nil {
fmt.Println("Error merging branches:", err)
os.Exit(1)
}
default:
fmt.Println("Unknown command:", command)
os.Exit(1)
}
}