comparison cmds/multipass-add/add.go @ 17:342f63116bfd

Move commands to canonical Go locations, so go install works.
author Paul Fisher <paul@pfish.zone>
date Fri, 30 Oct 2015 00:18:13 -0400
parents multipass-add.go@1246b4b9028b
children 00d30c67b56d
comparison
equal deleted inserted replaced
16:bfc035bd5132 17:342f63116bfd
1 // multipass-add allows a user to add an entry to their multipass database.
2
3 package main
4
5 import (
6 "bufio"
7 "fmt"
8 "os"
9
10 "pfish.zone/go/multipass/auth"
11 "pfish.zone/go/multipass/file"
12 )
13
14 func main() {
15 passfile, err := file.ForMe()
16 if err != nil {
17 fmt.Println(err.Error())
18 os.Exit(1)
19 }
20 reader := bufio.NewReader(os.Stdin)
21 fmt.Print("Describe password: ")
22 text, err := reader.ReadString('\n')
23 if err != nil {
24 fmt.Println(err.Error())
25 os.Exit(1)
26 }
27 text = text[:len(text)-1]
28 entry, password, err := auth.NewEntry(text)
29 if err != nil {
30 fmt.Println(err.Error())
31 os.Exit(1)
32 }
33 err = passfile.Add(entry)
34 if err != nil {
35 fmt.Println("Couldn't create a password:")
36 fmt.Println(err.Error())
37 os.Exit(1)
38 }
39 fmt.Printf("New password: %s\n", password)
40 }