CLI working

This commit is contained in:
Brian Buller 2017-01-25 14:13:26 -06:00
parent ea879bd57e
commit 566382e0ad

View File

@ -4,15 +4,46 @@ import (
"fmt" "fmt"
"os" "os"
"golang.org/x/crypto/ssh/terminal"
passage "gogs.bullercodeworks.com/brian/passage-go" passage "gogs.bullercodeworks.com/brian/passage-go"
) )
func main() { func main() {
if len(os.Args) < 3 { var pin, door string
fmt.Println("Usage: gopass <pin> <door>") for i := 1; i < len(os.Args); i++ {
os.Exit(1) switch i {
case 1:
pin = os.Args[i]
case 2:
door = os.Args[i]
}
} }
p := passage.CreatePassage(os.Args[1]) p := passage.CreatePassage("")
fmt.Println("Checksum: " + p.GetChecksumAsString()) getInput := (pin == "" && door == "")
fmt.Println("Password: " + p.GetPassword(os.Args[2])) 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))
} }