-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (77 loc) · 1.82 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
package main
import (
"fmt"
"os"
"strings"
"coreunit.net/vault/internal/config"
"coreunit.net/vault/internal/subcmd"
"coreunit.net/vault/lib/stringfs"
"github.com/joho/godotenv"
)
var DisplayName string = "Unset"
var ShortName string = "unset"
var Version string = "?.?.?"
var Commit string = "???????"
func main() {
err := godotenv.Load()
if err == nil {
fmt.Println("Environment variables from .env loaded")
}
appConfig := config.ParseConfig(Version, Commit)
stringfs.ParsePath(&appConfig.PublicKeyPath)
stringfs.ParsePath(&appConfig.PrivateKeyPath)
targetFile := targetFile(appConfig)
if appConfig.SubCommand == "lock" {
subcmd.LockOperation(
targetFile,
appConfig,
)
} else if appConfig.SubCommand == "init" {
subcmd.InitOperation(
targetFile,
appConfig,
)
} else if appConfig.SubCommand == "print" {
subcmd.PrintOperation(
targetFile,
appConfig,
)
} else if appConfig.SubCommand == "unlock" {
subcmd.UnlockOperation(
targetFile,
appConfig,
)
} else if appConfig.SubCommand == "temp" {
subcmd.TempOperation(
targetFile,
appConfig,
)
} else if appConfig.SubCommand == "passwd" {
subcmd.PasswdOperation(
targetFile,
appConfig,
)
} else {
fmt.Fprintf(
os.Stderr,
"%s: '"+appConfig.SubCommand+"' is not a command.\n"+
"See '%s help'",
os.Args[0],
os.Args[0],
)
}
}
func targetFile(
appConfig *config.AppConfig,
) string {
if len(appConfig.Args) >= 2 {
targetFile := appConfig.Args[1]
if strings.HasSuffix(targetFile, "."+appConfig.VaultFileExtension) {
targetFile = targetFile[:len(targetFile)-len(appConfig.VaultFileExtension)-1]
} else if strings.HasSuffix(targetFile, "."+appConfig.PlainFileExtension) {
targetFile = targetFile[:len(targetFile)-len(appConfig.PlainFileExtension)-1]
}
return targetFile
}
return "vault"
}