annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
1 // multipass-add allows a user to add an entry to their multipass database.
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
2
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
3 package main
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
4
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
5 import (
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
6 "bufio"
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
7 "fmt"
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
8 "os"
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
9
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
10 "pfish.zone/go/multipass/auth"
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
11 "pfish.zone/go/multipass/file"
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
12 )
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
13
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
14 func main() {
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
15 passfile, err := file.ForMe()
10
1246b4b9028b Add tool to remove passwords.
Paul Fisher <paul@pfish.zone>
parents: 7
diff changeset
16 if err != nil {
1246b4b9028b Add tool to remove passwords.
Paul Fisher <paul@pfish.zone>
parents: 7
diff changeset
17 fmt.Println(err.Error())
1246b4b9028b Add tool to remove passwords.
Paul Fisher <paul@pfish.zone>
parents: 7
diff changeset
18 os.Exit(1)
1246b4b9028b Add tool to remove passwords.
Paul Fisher <paul@pfish.zone>
parents: 7
diff changeset
19 }
0
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
20 reader := bufio.NewReader(os.Stdin)
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
21 fmt.Print("Describe password: ")
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
22 text, err := reader.ReadString('\n')
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
23 if err != nil {
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
24 fmt.Println(err.Error())
7
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
25 os.Exit(1)
0
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
26 }
2
a4fa4f28b472 Actually shave off last character of password description.
Paul Fisher <paul@pfish.zone>
parents: 1
diff changeset
27 text = text[:len(text)-1]
0
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
28 entry, password, err := auth.NewEntry(text)
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
29 if err != nil {
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
30 fmt.Println(err.Error())
7
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
31 os.Exit(1)
0
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
32 }
7
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
33 err = passfile.Add(entry)
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
34 if err != nil {
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
35 fmt.Println("Couldn't create a password:")
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
36 fmt.Println(err.Error())
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
37 os.Exit(1)
406d3cd76739 Report errors to the user.
Paul Fisher <paul@pfish.zone>
parents: 2
diff changeset
38 }
0
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
39 fmt.Printf("New password: %s\n", password)
c18bc7b9d1d9 Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff changeset
40 }