Mercurial > go > multipass
annotate remove.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-remove/remove.go@342f63116bfd |
| children |
| rev | line source |
|---|---|
| 11 | 1 // multipass-remove allows a user to remove an entry from their multipass database. |
| 2 | |
| 3 package main | |
| 4 | |
| 5 import ( | |
| 6 "bufio" | |
| 7 "fmt" | |
| 8 "os" | |
| 9 "strconv" | |
| 10 | |
| 11 "pfish.zone/go/multipass/file" | |
| 12 ) | |
| 13 | |
|
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
14 func remove(passfile *file.ShadowFile, input *bufio.Reader) int { |
| 11 | 15 fmt.Println("Choose a password to remove:") |
| 16 reader := bufio.NewReader(os.Stdin) | |
| 17 entries, err := passfile.AllEntries() | |
| 18 for i, entry := range entries { | |
| 19 fmt.Printf("%2d: %s\n", i+1, entry.Description()) | |
| 20 } | |
| 21 fmt.Print("Enter the number to remove: ") | |
| 22 text, err := reader.ReadString('\n') | |
| 23 if err != nil { | |
| 24 fmt.Println(err.Error()) | |
|
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
25 return 1 |
| 11 | 26 } |
| 27 picked, err := strconv.Atoi(text[:len(text)-1]) | |
| 28 if err != nil { | |
| 29 fmt.Println("Not a valid number") | |
|
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
30 return 1 |
| 11 | 31 } |
| 32 picked -= 1 | |
| 33 if picked < 0 || len(entries) <= picked { | |
| 34 fmt.Println("Not a valid selection") | |
|
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
35 return 1 |
| 11 | 36 } |
| 37 | |
| 38 if err := passfile.Remove(entries[picked].ID()); err != nil { | |
| 39 fmt.Printf("Couldn't remove password: %s\n", err.Error()) | |
|
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
40 return 1 |
| 11 | 41 } |
| 42 fmt.Println("Removed password entry.") | |
|
19
58fe867c9ecf
Reorganize commands to more standard go layout.
Paul Fisher <paul@pfish.zone>
parents:
17
diff
changeset
|
43 return 0 |
| 11 | 44 } |
