changeset 11:e246c8a4d28e

Actually add the remove command.
author Paul Fisher <paul@pfish.zone>
date Sun, 25 Oct 2015 11:48:53 -0400
parents 1246b4b9028b
children 1c194fa9bbf4
files multipass-remove.go
diffstat 1 files changed, 48 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/multipass-remove.go	Sun Oct 25 11:48:53 2015 -0400
@@ -0,0 +1,48 @@
+// multipass-remove allows a user to remove an entry from their multipass database.
+
+package main
+
+import (
+	"bufio"
+	"fmt"
+	"os"
+	"strconv"
+
+	"pfish.zone/go/multipass/file"
+)
+
+func main() {
+	passfile, err := file.ForMe()
+	if err != nil {
+		fmt.Println(err.Error())
+		os.Exit(1)
+	}
+	fmt.Println("Choose a password to remove:")
+	reader := bufio.NewReader(os.Stdin)
+	entries, err := passfile.AllEntries()
+	for i, entry := range entries {
+		fmt.Printf("%2d: %s\n", i+1, entry.Description())
+	}
+	fmt.Print("Enter the number to remove: ")
+	text, err := reader.ReadString('\n')
+	if err != nil {
+		fmt.Println(err.Error())
+		os.Exit(1)
+	}
+	picked, err := strconv.Atoi(text[:len(text)-1])
+	if err != nil {
+		fmt.Println("Not a valid number")
+		os.Exit(1)
+	}
+	picked -= 1
+	if picked < 0 || len(entries) <= picked {
+		fmt.Println("Not a valid selection")
+		os.Exit(1)
+	}
+
+	if err := passfile.Remove(entries[picked].ID()); err != nil {
+		fmt.Printf("Couldn't remove password: %s\n", err.Error())
+		os.Exit(1)
+	}
+	fmt.Println("Removed password entry.")
+}