78 lines
1.1 KiB
Go
78 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
|
|
"git.wow.st/gmp/passgo"
|
|
)
|
|
|
|
func usage() {
|
|
fmt.Println("passgo [-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() {
|
|
var store passgo.Store
|
|
err := passgo.GetStore(&store)
|
|
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 {
|
|
passgo.Clip(p)
|
|
} else {
|
|
fmt.Println(p)
|
|
}
|
|
default:
|
|
usage()
|
|
}
|
|
}
|