-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (51 loc) · 1.13 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
package main
import (
"fmt"
"log"
"os"
"github.com/Param-Singh/go-cli-vault/helpers"
"github.com/atotto/clipboard"
)
func main() {
args := os.Args[1:]
if len(args) == 0 {
fmt.Println("No arguments provided\nuse help to see the help menu")
return
}
if !helpers.DoesDirExist(".vault-password") {
// Create an hidden folder
if err := os.Mkdir(".vault-password", 0755); err != nil {
log.Fatal(err)
}
}
if args[0] == "help" {
helpers.PrintHelpMenu()
return
}
// Read Passwords stored in the hidden in file
helpers.MakeDir()
b := helpers.ReadFile()
helpers.GetAllPasswords(b)
if args[0] == "set" {
err := helpers.UpdateAndSavePasswords(b, args[1], args[2])
if err != nil {
fmt.Println(err)
}
return
}
if args[0] == "get" {
key := args[1]
password := helpers.GetUserChosenPassword(key)
err := clipboard.WriteAll(password)
if err != nil {
fmt.Println("Failed to copy to clipboard")
fmt.Println(err)
}
fmt.Println("Password copied to clipboard !!")
}
if args[0] == "getall" {
for site := range helpers.PasswordMap {
fmt.Println(site, "=> ", helpers.GetUserChosenPassword(site))
}
}
}