Rename to passgo and run go fmt.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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() {
|
||||
store, err := passgo.GetStore()
|
||||
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.Print(p)
|
||||
}
|
||||
default:
|
||||
usage()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user