2019-09-04 22:19:39 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
2019-09-04 22:32:19 -04:00
|
|
|
"git.wow.st/gmp/gpass"
|
2019-09-04 22:19:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
fmt.Println("gpass [-c|--clip] [name]")
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
type options struct {
|
|
|
|
clip bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func parse(args []string) ([]string,options) {
|
|
|
|
ret := make([]string,0)
|
|
|
|
opts := options{}
|
|
|
|
for _,a := range args {
|
|
|
|
switch {
|
|
|
|
case a == "-c",a == "--clip":
|
|
|
|
opts.clip = true
|
|
|
|
case a[0] == '-':
|
|
|
|
usage()
|
|
|
|
default:
|
|
|
|
ret = append(ret,a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret,opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2019-09-04 22:32:19 -04:00
|
|
|
store,err := gpass.GetStore()
|
2019-09-04 22:19:39 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
args := os.Args[1:]
|
|
|
|
args,opts := parse(args)
|
|
|
|
switch len(args) {
|
|
|
|
case 0:
|
|
|
|
l,err := store.List()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
for _, x := range l {
|
|
|
|
_, n := path.Split(x.Pathname)
|
|
|
|
s := strings.Repeat(" /",x.Level)
|
|
|
|
z := ""
|
|
|
|
if x.Dir { z = "/" }
|
|
|
|
fmt.Println(strings.Join([]string{s,n,z},""))
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
p,err := store.Decrypt(args[0])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
if opts.clip {
|
2019-09-04 22:32:19 -04:00
|
|
|
gpass.Clip(p)
|
2019-09-04 22:19:39 -04:00
|
|
|
} else {
|
|
|
|
fmt.Print(p)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
usage()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|