comparison multipass-remove.go @ 11:e246c8a4d28e

Actually add the remove command.
author Paul Fisher <paul@pfish.zone>
date Sun, 25 Oct 2015 11:48:53 -0400
parents
children
comparison
equal deleted inserted replaced
10:1246b4b9028b 11:e246c8a4d28e
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
14 func main() {
15 passfile, err := file.ForMe()
16 if err != nil {
17 fmt.Println(err.Error())
18 os.Exit(1)
19 }
20 fmt.Println("Choose a password to remove:")
21 reader := bufio.NewReader(os.Stdin)
22 entries, err := passfile.AllEntries()
23 for i, entry := range entries {
24 fmt.Printf("%2d: %s\n", i+1, entry.Description())
25 }
26 fmt.Print("Enter the number to remove: ")
27 text, err := reader.ReadString('\n')
28 if err != nil {
29 fmt.Println(err.Error())
30 os.Exit(1)
31 }
32 picked, err := strconv.Atoi(text[:len(text)-1])
33 if err != nil {
34 fmt.Println("Not a valid number")
35 os.Exit(1)
36 }
37 picked -= 1
38 if picked < 0 || len(entries) <= picked {
39 fmt.Println("Not a valid selection")
40 os.Exit(1)
41 }
42
43 if err := passfile.Remove(entries[picked].ID()); err != nil {
44 fmt.Printf("Couldn't remove password: %s\n", err.Error())
45 os.Exit(1)
46 }
47 fmt.Println("Removed password entry.")
48 }