Mercurial > go > multipass
view 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 |
line wrap: on
line source
// 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 remove(passfile *file.ShadowFile, input *bufio.Reader) int { 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()) return 1 } picked, err := strconv.Atoi(text[:len(text)-1]) if err != nil { fmt.Println("Not a valid number") return 1 } picked -= 1 if picked < 0 || len(entries) <= picked { fmt.Println("Not a valid selection") return 1 } if err := passfile.Remove(entries[picked].ID()); err != nil { fmt.Printf("Couldn't remove password: %s\n", err.Error()) return 1 } fmt.Println("Removed password entry.") return 0 }