-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (69 loc) · 1.52 KB
/
main.go
File metadata and controls
76 lines (69 loc) · 1.52 KB
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
package main
import (
"flag"
"fmt"
"os"
"github.com/WithGJR/regit-go/core"
)
func main() {
commitCmd := flag.NewFlagSet("commit", flag.ExitOnError)
var commitMessage string
commitCmd.StringVar(&commitMessage, "m", "", "A commmit message")
workingDir, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(os.Args) < 2 {
fmt.Println("command too short")
os.Exit(1)
}
regit := core.NewReGit(workingDir)
switch os.Args[1] {
case "init":
regit.Init()
case "add":
if len(os.Args) == 2 {
fmt.Println("Nothing specified, nothing added.")
os.Exit(1)
}
regit.Add(os.Args[2:])
case "commit":
commitCmd.Parse(os.Args[2:])
if commitMessage == "" {
fmt.Println("-m option is required.")
os.Exit(1)
}
regit.Commmit(commitMessage)
case "checkout":
if len(os.Args) == 2 {
fmt.Println("Error: you need to specify path names")
os.Exit(1)
}
regit.Checkout(os.Args[2:])
case "branch":
if len(os.Args) == 2 {
fmt.Println("Error: you need to specify the branch name")
os.Exit(1)
}
if len(os.Args) > 3 {
fmt.Println("Error: you can only specify one branch name")
os.Exit(1)
}
regit.CreateBranch(os.Args[2])
case "log":
if len(os.Args) > 3 {
fmt.Println("Error: `log` command does not accept arguments")
os.Exit(1)
}
regit.Log()
case "merge":
if len(os.Args) > 3 {
fmt.Println("Error: you can only supply one branch name")
os.Exit(1)
}
regit.Merge(os.Args[2])
default:
fmt.Println("'" + os.Args[1] + "' is not a ReGit command.")
}
}