Mercurial > go > multipass
annotate add.go @ 19:58fe867c9ecf
Reorganize commands to more standard go layout.
- Unify multipass user commands under one 'multipass' binary
- Move multipass checkpassword command to mp-checkpassword.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 01 Nov 2015 12:42:02 -0500 |
parents | cmds/multipass-add/add.go@00d30c67b56d |
children |
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/file" |
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
11 ) |
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
12 |
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
18
diff
changeset
|
13 func add(passfile *file.ShadowFile, input *bufio.Reader) int { |
0
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
14 reader := bufio.NewReader(os.Stdin) |
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
15 fmt.Print("Describe password: ") |
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
16 text, err := reader.ReadString('\n') |
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
17 if err != nil { |
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
18 fmt.Println(err.Error()) |
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
18
diff
changeset
|
19 return 1 |
0
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
20 } |
2
a4fa4f28b472
Actually shave off last character of password description.
Paul Fisher <paul@pfish.zone>
parents:
1
diff
changeset
|
21 text = text[:len(text)-1] |
18
00d30c67b56d
Put all the library stuff into multipass/file.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
22 entry, password, err := file.NewEntry(text) |
0
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()) |
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
18
diff
changeset
|
25 return 1 |
0
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
26 } |
7 | 27 err = passfile.Add(entry) |
28 if err != nil { | |
29 fmt.Println("Couldn't create a password:") | |
30 fmt.Println(err.Error()) | |
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
18
diff
changeset
|
31 return 1 |
7 | 32 } |
0
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
33 fmt.Printf("New password: %s\n", password) |
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
18
diff
changeset
|
34 return 0 |
0
c18bc7b9d1d9
Basic binaries. checkpassword doesn't yet work.
Paul Fisher <paul@pfish.zone>
parents:
diff
changeset
|
35 } |