-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (91 loc) · 3.21 KB
/
main.go
File metadata and controls
98 lines (91 loc) · 3.21 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
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 (
"rdvc/init_dir"
"rdvc/networking"
"os"
"strings"
"github.com/pterm/pterm"
)
var (
currentRepoName string
currentRepoPath string
)
func printHelp() {
pterm.FgGreen.Println("rdvc - RainDrops Version Control")
pterm.FgBlue.Println("Usage:")
pterm.FgCyan.Println(" rdvc init -p <path_to_directory> -n <repo_name> Initialize a controlled directory")
pterm.FgCyan.Printfln(" rdvc keep -m <message> -u <user_name> -n <repo_name> Keep changes with a message")
pterm.FgCyan.Printfln(" rdvc line -n <repo_name> -o <name_line> Create line for current changes in repo")
pterm.FgCyan.Printfln(" rdvc checkout -n <repo_name> -o <line_name> Go to line")
pterm.FgCyan.Printfln(" ")
pterm.FgCyan.Printfln(" rdvc set -u <username> -p <password> Setup config for cloud storage")
pterm.FgCyan.Printfln(" rdvc send -n <repo_name> Send keeped changes to cloud")
pterm.FgCyan.Printfln(" rdvc get -n <repo_name> Get list changes from repo in cloud")
pterm.FgCyan.Printfln(" rdvc roll -n <repo_name> Pullback to choosed version of file")
pterm.FgCyan.Printfln(" rdvc load -n <repo_name> Rollback to choosed version of file in cloud")
pterm.FgCyan.Printfln(" ")
pterm.FgMagenta.Printfln(" rdvc help Display this help message")
}
func check_args(){
if len(os.Args) < 2 {
printHelp()
return
}
switch os.Args[1]{
case "help":
printHelp()
return
case "init":
pathFlag := os.Args[3]
init_dir.InitInvisible(pathFlag)
init_dir.CreateSettings(pathFlag, os.Args[5])
case "keep":
repoPath := init_dir.ReadFromReg(os.Args[7])
versionControl := init_dir.NewVCS(repoPath)
message := os.Args[3]
author := os.Args[5]
err := versionControl.MakeKeep(message, author)
if err != nil {
pterm.Error.Println("Error in keeping:", err)
}
case "line":
repoPath := init_dir.ReadFromReg(os.Args[3])
vcs := init_dir.NewVCS(repoPath)
err := vcs.CreateBranch(os.Args[5])
if err != nil {
pterm.Error.Println("Error creating line:", err)
return
}
case "checkout":
repoPath := init_dir.ReadFromReg(os.Args[3])
vcs := init_dir.NewVCS(repoPath)
err := vcs.CheckoutBranch(os.Args[5])
if err != nil {
pterm.Error.Println("Ошибка переключения на ветку:", err)
return
}
case "send":
networking.UploadKeeps(os.Args[3])
case "get":
networking.GetKeeps(os.Args[3])
case "set":
networking.Connect(os.Args[3], os.Args[5])
reg_data := []string{os.Args[3], os.Args[5]}
init_dir.CreateSettings( strings.Join(reg_data, ","), "reg_data" )
case "roll":
vcs := init_dir.NewVCS(os.Args[3])
err := vcs.Rollback()
if err != nil {
pterm.Error.Println("Error pullback:", err)
return
}
case "load":
networking.GetLastKeepFromCloud(os.Args[3])
default:
pterm.Error.Printfln("Unknown command: %s\n", os.Args[1])
printHelp()
}
}
func main() {
check_args()
}