-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (53 loc) · 1.23 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
/* Version */
const (
major = 1
minor = 1
patch = 1
)
/* Example of the record in the database */
type Record struct {
Title string `json:"Title"`
Username string `json:"Username"`
Password string `json:"Password"`
Description string `json:"Description"`
}
type Category struct {
CategoryName string `json:"Category_Name"`
Records []Record `json:"Record"`
}
func main() {
newDB := flag.Bool("n", false, "Create a new database")
argPath := flag.String("f", "", "Pipe the database into nspm")
flag.Parse()
var dbName, dbPath string
var dbPass []byte
if *newDB {
createNewDatabase()
os.Exit(0)
}
if *argPath != "" {
dbPath = *argPath
if _, err := os.Stat(dbPath); err != nil {
fmt.Println("The database doesn't exist.")
os.Exit(0)
}
dbName = filepath.Base(dbPath)
} else {
dbName, dbPath = getDatabasePath(getDatabaseFolder())
if dbName == "" && dbPath == "" {
fmt.Println("Databases were not found. Consider creating a new database via -n")
os.Exit(0)
}
}
dbPass = *getDerivedPassword(readDatabasePassword())
db := unmarshalDatabase(decrypt(dbPass, dbPath))
mainMenu(db, &dbName, &dbPath, &dbPass)
clearScreen()
}