-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (81 loc) · 1.47 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
package main
import (
"fmt"
"os"
)
func main() {
args := os.Args
if len(args) < 1 {
fmt.Println("No tgit command found")
displayHelp()
return
}
switch args[1] {
case "init":
{
err := initRepo()
if err != nil {
fmt.Println(err)
}
}
case "help":
{
if !repoExists() {
fmt.Println("Repository not initialized")
return
}
displayHelp()
}
case "checkout":
{
checkout(args[2:])
}
case "add":
{
if !repoExists() {
fmt.Println("Repository not initialized")
return
}
err := add(args[2:])
if err != nil {
fmt.Println(err)
}
}
case "commit":
{
if !repoExists() {
fmt.Println("Repository not initialized")
return
}
if err := commit(args[2:]); err != nil {
fmt.Println(err)
}
}
case "branch":
{
if !repoExists() {
fmt.Println("Repository not initialized")
return
}
if err := branch(args[2:]); err != nil {
fmt.Println(err)
}
}
default:
{
fmt.Println("Invalid command", args[0])
displayHelp()
}
}
}
func displayHelp() {
fmt.Println("Tiny Git by humanbeeng!")
fmt.Println("Available commands:")
fmt.Println("\tinit: Initializes an empty tgit repository ")
fmt.Println("\tadd: Adds files to staging")
fmt.Println("\tcommit: Commit staged files")
fmt.Println("\tbranch: Creates a new branch")
fmt.Println("\tcheckout: Checkout to branch")
fmt.Println("\tclone: Clones a remote repository")
fmt.Println("\thelp: Display this help message")
}