forked from zendesk/vault-backend-migrator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
79 lines (67 loc) · 1.28 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
package main
import (
"flag"
"fmt"
"github.com/msharbaji/vault-backend-migrator/cmd"
"os"
"strings"
)
var (
// Actions
ex = flag.String("export", "", "The vault path to export")
im = flag.String("import", "", "The vault path to import data into")
// Required during export or import
file = flag.String("file", "", "The local file location to use")
// Output the version
version = flag.Bool("version", false, "Output the version number")
)
const Version = "0.2.1-dev"
func main() {
flag.Parse()
// Import
if im != nil && *im != "" {
if empty(im, file) {
exit()
}
err := cmd.Import(*im, *file)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return
}
// Export
if ex != nil && *ex != "" {
if empty(ex, file) {
exit()
}
err := cmd.Export(*ex, *file)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return
}
// Version
if version != nil && *version {
fmt.Println(Version)
os.Exit(1)
}
// No commands, print help.
flag.Usage()
os.Exit(1)
}
// Do we have any empty strings?
func empty(s ...*string) bool {
for _, v := range s {
if v == nil || len(strings.TrimSpace(*v)) == 0 {
return true
}
}
return false
}
func exit() {
fmt.Println("There was an error reading your config flags, please fix")
flag.Usage()
os.Exit(1)
}