comparison 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
comparison
equal deleted inserted replaced
18:00d30c67b56d 19:58fe867c9ecf
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 remove(passfile *file.ShadowFile, input *bufio.Reader) int {
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())
25 return 1
26 }
27 picked, err := strconv.Atoi(text[:len(text)-1])
28 if err != nil {
29 fmt.Println("Not a valid number")
30 return 1
31 }
32 picked -= 1
33 if picked < 0 || len(entries) <= picked {
34 fmt.Println("Not a valid selection")
35 return 1
36 }
37
38 if err := passfile.Remove(entries[picked].ID()); err != nil {
39 fmt.Printf("Couldn't remove password: %s\n", err.Error())
40 return 1
41 }
42 fmt.Println("Removed password entry.")
43 return 0
44 }