From 566382e0ad87af87c6f6a729cee8019b1d29fe0d Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 25 Jan 2017 14:13:26 -0600 Subject: [PATCH] CLI working --- gopass-cmd/main.go | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/gopass-cmd/main.go b/gopass-cmd/main.go index 9e08774..7094cff 100644 --- a/gopass-cmd/main.go +++ b/gopass-cmd/main.go @@ -4,15 +4,46 @@ import ( "fmt" "os" + "golang.org/x/crypto/ssh/terminal" + passage "gogs.bullercodeworks.com/brian/passage-go" ) func main() { - if len(os.Args) < 3 { - fmt.Println("Usage: gopass ") - os.Exit(1) + var pin, door string + for i := 1; i < len(os.Args); i++ { + switch i { + case 1: + pin = os.Args[i] + case 2: + door = os.Args[i] + } } - p := passage.CreatePassage(os.Args[1]) - fmt.Println("Checksum: " + p.GetChecksumAsString()) - fmt.Println("Password: " + p.GetPassword(os.Args[2])) + p := passage.CreatePassage("") + getInput := (pin == "" && door == "") + for getInput { + if pin == "" { + fmt.Print("Pin: ") + pinBt, _ := terminal.ReadPassword(0) + fmt.Println("") + pin = string(pinBt) + } + if pin == "" { + continue + } else { + p.SetPin(pin) + fmt.Println("Checksum: " + p.GetChecksumAsString()) + } + if door == "" { + fmt.Print("Door (leave empty to re-enter pin): ") + fmt.Scanln(&door) + } + if door == "" { + pin = "" + } else { + getInput = false + } + } + + fmt.Println(p.GetPassword(door)) }