-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (72 loc) · 1.51 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
package main
import (
"flag"
"fmt"
"io"
"os"
"sync"
"github.com/jmoiron/sqlx"
log "github.com/sirupsen/logrus"
"github.com/johnshiver/pappy/config"
)
type runEnv struct {
userInput io.Reader
userSvc UserService
pwdSvc PasswordService
user *User
encryptionKey []byte
mtx sync.Mutex
}
func init() {
log.SetOutput(os.Stdout)
log.SetLevel(log.WarnLevel)
}
func initEnv(db *sqlx.DB) *runEnv {
var env runEnv
env.userInput = os.Stdin
env.userSvc = NewUserDao(db)
env.pwdSvc = NewPasswordDao(db)
return &env
}
func (env *runEnv) createTables() {
env.userSvc.CreateUserTable()
env.pwdSvc.CreatePasswordsTable()
}
func main() {
db := config.GetDB()
defer db.Close()
env := initEnv(db)
env.createTables()
tgtObject := flag.String("o", "", "object to perform action on: user / password")
action := flag.String("a", "", "action to perform on object: create / list / delete")
flag.Parse()
switch *tgtObject {
case "user", "u":
switch *action {
case "create", "c":
env.CreateUser()
case "list", "l":
// this is a security hazard, I dont really care for my personal use
env.ListUsers()
}
case "password", "p":
switch *action {
case "create", "c":
env.LogIn()
env.CreatePassword()
case "list", "l":
env.LogIn()
env.ListPasswords()
case "delete", "d":
env.LogIn()
env.DeletePassword()
}
default:
switch *action {
case "gen", "generate", "g":
fmt.Println(generatePassword(-1))
case "db", "dbloc":
fmt.Println(config.GetDBFilePath())
}
}
}