-
Notifications
You must be signed in to change notification settings - Fork 2
/
backup.go
171 lines (142 loc) · 2.97 KB
/
backup.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/onerobotics/backup/project"
)
var filters map[string][]string
var robotNamelistFlag project.RobotNamelist
func init() {
filters = make(map[string][]string)
filters["all"] = []string{"*.*"}
filters["tp"] = []string{"*.tp"}
filters["ls"] = []string{"*.ls"}
filters["vr"] = []string{"*.vr"}
filters["va"] = []string{"*.va"}
filters["sv"] = []string{"*.sv"}
filters["vision"] = []string{"*.vd", "*.vda", "*.zip"}
filters["app"] = []string{"*.tp", "numreg.vr", "posreg.vr"}
filters["ascii"] = []string{"*.ls", "*.va", "*.dat", "*.dg", "*.xml"}
filters["bin"] = []string{"*.zip", "*.sv", "*.tp", "*.vr"}
flag.Var(&robotNamelistFlag, "r", "comma-separated list of robot names")
}
func usage() {
fmt.Println(`
BackupTool v1.0.1
-----------------
FANUC robot backups made easy by ONE Robotics Company.
Author: Jay Strybis <[email protected]>
Website: https://www.onerobotics.com
Usage:
backuptool command [arguments]
The commands are:
add, a Add a robot to a project
backup, b Perform a backup
remove, r Remove a robot from a project
help, h Show this screen or command-specific help`)
}
func addUsage() {
fmt.Println(`
usage: backuptool add
Follow the instructions in the CLI wizard to add a robot
to the current project.`)
}
func backupUsage() {
fmt.Printf(`
usage: backuptool backup [flags] filter
The filters are:
all *.*
tp *.tp
ls *.ls
vr *.vr
va *.va
sv *.sv
vision *.vd, *.vda, *.zip
app *.tp, numreg.vr, posreg.vr
ascii *.ls, *.va, *.dat, *.dg, *.xml
bin *.zip, *.sv, *.tp, *.vr
The flags are:
-r comma-separated list of robot names
Used to backup a subset of the project's robots
`)
}
func removeUsage() {
fmt.Println(`
usage: backuptool remove
Follow the CLI wizard to remove a robot from your project`)
}
func main() {
flag.Parse()
args := flag.Args()
p, err := project.Init()
if err != nil {
log.Fatal(err)
}
if len(args) < 1 {
usage()
os.Exit(0)
}
switch args[0] {
case "add", "a":
if len(args) > 1 {
addUsage()
os.Exit(1)
}
err := p.AddRobot()
if err != nil {
log.Fatal(err)
}
case "backup", "b":
if len(args) < 2 {
backupUsage()
os.Exit(1)
}
filter, ok := filters[args[1]]
if !ok {
fmt.Printf("Invalid filter: %s\n", args[1])
backupUsage()
os.Exit(1)
}
err := p.Backup(robotNamelistFlag, func(filename string) bool {
for _, f := range filter {
if f[0] == '*' {
return filepath.Ext(filename) == f[1:]
} else {
return filename == f
}
}
return false
}, args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case "remove", "r":
if len(args) > 1 {
removeUsage()
os.Exit(1)
}
err := p.RemoveRobot()
if err != nil {
log.Fatal(err)
}
case "help", "h":
if len(args) < 2 {
usage()
return
}
switch args[1] {
case "add", "a":
addUsage()
case "backup", "b":
backupUsage()
case "remove", "r":
removeUsage()
}
default:
usage()
}
}