Mercurial > go > multipass
diff cmds/multipass-add/add.go @ 17:342f63116bfd
Move commands to canonical Go locations, so go install works.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Fri, 30 Oct 2015 00:18:13 -0400 |
parents | multipass-add.go@1246b4b9028b |
children | 00d30c67b56d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmds/multipass-add/add.go Fri Oct 30 00:18:13 2015 -0400 @@ -0,0 +1,40 @@ +// multipass-add allows a user to add an entry to their multipass database. + +package main + +import ( + "bufio" + "fmt" + "os" + + "pfish.zone/go/multipass/auth" + "pfish.zone/go/multipass/file" +) + +func main() { + passfile, err := file.ForMe() + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + reader := bufio.NewReader(os.Stdin) + fmt.Print("Describe password: ") + text, err := reader.ReadString('\n') + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + text = text[:len(text)-1] + entry, password, err := auth.NewEntry(text) + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + err = passfile.Add(entry) + if err != nil { + fmt.Println("Couldn't create a password:") + fmt.Println(err.Error()) + os.Exit(1) + } + fmt.Printf("New password: %s\n", password) +}