-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (64 loc) · 1.97 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
package main
import (
"flag"
"fmt"
"os"
"github.com/anonmanak/PassLock/implementation"
)
func main() {
if len(os.Args) < 2 || os.Args[1] == "-help" {
implementation.PrintUsage()
return
}
operation := os.Args[1]
pm, err := implementation.NewPasswordManager()
if err != nil {
fmt.Println("An error occured: ", err)
return
}
switch operation {
case "-add-password":
var tag, password string
var generate bool
flagSet := flag.NewFlagSet("add-password", flag.ExitOnError)
flagSet.StringVar(&tag, "tag", "", "Specify the tag.")
flagSet.StringVar(&password, "password", "", "Specify the password.")
flagSet.BoolVar(&generate, "generate", false, "Generate a strong password.")
flagSet.Parse(os.Args[2:])
err := pm.AddPasswordWithTag(tag, password, generate)
if err != nil {
fmt.Println("An error occured: ", err)
}
case "-update-password":
var tag, password string
var generate bool
flagSet := flag.NewFlagSet("update-password", flag.ExitOnError)
flagSet.StringVar(&tag, "tag", "", "Specify the tag.")
flagSet.StringVar(&password, "password", "", "Specify the new password.")
flagSet.BoolVar(&generate, "generate", false, "Generate a new strong password.")
flagSet.Parse(os.Args[2:])
err := pm.UpdatePasswordWithTag(tag, password, generate)
if err != nil {
fmt.Println("An error occured: ", err)
}
case "-delete-password":
var tag string
flagSet := flag.NewFlagSet("delete-password", flag.ExitOnError)
flagSet.StringVar(&tag, "tag", "", "Specify the tag.")
flagSet.Parse(os.Args[2:])
err := pm.DeletePasswordWithTag(tag)
if err != nil {
fmt.Println("An error occured: ", err)
}
case "-get-password":
var tag string
flagSet := flag.NewFlagSet("get-password", flag.ExitOnError)
flagSet.StringVar(&tag, "tag", "", "Specify the tag.")
flagSet.Parse(os.Args[2:])
pm.GetPasswordWithTag(tag)
case "-get-tags":
pm.GetAllTags()
default:
fmt.Println("Invalid operation. Please use -help command to see all options.")
}
}