Rename to passgo and run go fmt.

This commit is contained in:
Greg 2019-09-05 06:41:39 -04:00
parent fc7a4c272e
commit 28ccd6d107
8 changed files with 135 additions and 138 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
cmd/gpass/gpass cmd/gpass/passgo
cmd/gpass-gui/gpass-gui cmd/gpass-gui/passgo-gui

View File

@ -1,4 +1,4 @@
# gpass # passgo
This repository includes Go code to interact with pass, the Unix password This repository includes Go code to interact with pass, the Unix password
manager. Library code is provided to open a password store, list manager. Library code is provided to open a password store, list
@ -7,7 +7,7 @@ a simple passphrase input function, or, if gpg-agent is running (on MacOS),
it will connect automatically to request your GPG passphrase. it will connect automatically to request your GPG passphrase.
```go ```go
store, err := gpass.GetStore() store, err := passgo.GetStore()
if err != nil { ... } if err != nil { ... }
passlist := store.List() passlist := store.List()
//storeDir := store.Dir //storeDir := store.Dir
@ -15,7 +15,7 @@ for _,x := range passlist {
if x.Pathname = "myPass" { if x.Pathname = "myPass" {
p, err := store.Decrypt(x.Pathname) p, err := store.Decrypt(x.Pathname)
if err == nil { if err == nil {
gpass.Clip(p) // put on the clipboard passgo.Clip(p) // put on the clipboard
} else { } else {
log.Fatal("Cannot decrypt ", x.Pathname) log.Fatal("Cannot decrypt ", x.Pathname)
} }

View File

@ -1,28 +0,0 @@
package main
import (
golog "log"
"os"
)
type logLevelT int
const (
Fatal logLevelT = 1 << iota
Error
Warn
Info
Debug
DebugGfx
)
var loglevel = Fatal | Error | Warn | Info
func log(level logLevelT, msg ...interface{}) {
if level & loglevel != 0 {
golog.Print(msg...)
}
if level & Fatal != 0 {
os.Exit(-1)
}
}

28
cmd/passgo-gui/log.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
golog "log"
"os"
)
type logLevelT int
const (
Fatal logLevelT = 1 << iota
Error
Warn
Info
Debug
DebugGfx
)
var loglevel = Fatal | Error | Warn | Info
func log(level logLevelT, msg ...interface{}) {
if level&loglevel != 0 {
golog.Print(msg...)
}
if level&Fatal != 0 {
os.Exit(-1)
}
}

View File

@ -4,35 +4,34 @@ package main
import ( import (
//"fmt" //"fmt"
"path"
"strings"
"image" "image"
"image/color" "image/color"
"path"
"strings"
"sync" "sync"
"gioui.org/ui" "gioui.org/ui"
"gioui.org/ui/app" "gioui.org/ui/app"
"gioui.org/ui/f32"
"gioui.org/ui/gesture"
"gioui.org/ui/input" "gioui.org/ui/input"
"gioui.org/ui/key" "gioui.org/ui/key"
"gioui.org/ui/layout" "gioui.org/ui/layout"
"gioui.org/ui/text"
"gioui.org/ui/measure" "gioui.org/ui/measure"
"gioui.org/ui/f32"
"gioui.org/ui/paint" "gioui.org/ui/paint"
"gioui.org/ui/gesture"
"gioui.org/ui/pointer" "gioui.org/ui/pointer"
"gioui.org/ui/text"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"golang.org/x/image/font/gofont/goregular" "golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/font/sfnt" "golang.org/x/image/font/sfnt"
"git.wow.st/gmp/passgo"
"git.wow.st/gmp/gpass"
) )
func main() { func main() {
var err error var err error
store,err = gpass.GetStore() store, err = passgo.GetStore()
if err != nil { if err != nil {
log(Fatal, err) log(Fatal, err)
} }
@ -45,9 +44,9 @@ func main() {
} }
var ( var (
l []gpass.Pass l []passgo.Pass
mux sync.Mutex mux sync.Mutex
store *gpass.Store store *passgo.Store
updated chan struct{} updated chan struct{}
) )
@ -114,7 +113,6 @@ func rrect(ops *ui.Ops, width, height, se, sw, nw, ne float32) {
b.End() b.End()
} }
func (b *Button) Layout(c ui.Config, ops *ui.Ops, q input.Queue, cs layout.Constraints) layout.Dimensions { func (b *Button) Layout(c ui.Config, ops *ui.Ops, q input.Queue, cs layout.Constraints) layout.Dimensions {
b.clicked = false b.clicked = false
for ev, ok := b.Click.Next(q); ok; ev, ok = b.Click.Next(q) { for ev, ok := b.Click.Next(q); ok; ev, ok = b.Click.Next(q) {
@ -178,7 +176,9 @@ func eventLoop() {
_, n := path.Split(x.Pathname) _, n := path.Split(x.Pathname)
s := strings.Repeat(" /", x.Level) s := strings.Repeat(" /", x.Level)
z := "" z := ""
if x.Dir { z = "/" } if x.Dir {
z = "/"
}
passBtns = append(passBtns, &Button{ passBtns = append(passBtns, &Button{
Face: face, Face: face,
Label: strings.Join([]string{s, n, z}, ""), Label: strings.Join([]string{s, n, z}, ""),
@ -190,7 +190,6 @@ func eventLoop() {
} }
updateBtns() updateBtns()
for { for {
select { select {
case <-updated: case <-updated:
@ -224,7 +223,7 @@ func eventLoop() {
//p,err := store.Decrypt(name, prompt) //p,err := store.Decrypt(name, prompt)
p, err := store.Decrypt(name) p, err := store.Decrypt(name)
if err == nil { if err == nil {
gpass.Clip(p) passgo.Clip(p)
} else { } else {
log(Info, "Can't decrypt ", name) log(Info, "Can't decrypt ", name)
log(Info, err) log(Info, err)
@ -240,4 +239,3 @@ func eventLoop() {
} }
} }
} }

View File

@ -6,11 +6,11 @@ import (
"path" "path"
"strings" "strings"
"git.wow.st/gmp/gpass" "git.wow.st/gmp/passgo"
) )
func usage() { func usage() {
fmt.Println("gpass [-c|--clip] [name]") fmt.Println("passgo [-c|--clip] [name]")
os.Exit(-1) os.Exit(-1)
} }
@ -35,7 +35,7 @@ func parse(args []string) ([]string,options) {
} }
func main() { func main() {
store,err := gpass.GetStore() store, err := passgo.GetStore()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(-1) os.Exit(-1)
@ -54,7 +54,9 @@ func main() {
_, n := path.Split(x.Pathname) _, n := path.Split(x.Pathname)
s := strings.Repeat(" /", x.Level) s := strings.Repeat(" /", x.Level)
z := "" z := ""
if x.Dir { z = "/" } if x.Dir {
z = "/"
}
fmt.Println(strings.Join([]string{s, n, z}, "")) fmt.Println(strings.Join([]string{s, n, z}, ""))
} }
case 1: case 1:
@ -64,7 +66,7 @@ func main() {
os.Exit(-1) os.Exit(-1)
} }
if opts.clip { if opts.clip {
gpass.Clip(p) passgo.Clip(p)
} else { } else {
fmt.Print(p) fmt.Print(p)
} }
@ -72,4 +74,3 @@ func main() {
usage() usage()
} }
} }

View File

@ -1,11 +1,11 @@
//+build !android !linux //+build !android !linux
package gpass package passgo
import ( import (
"fmt"
"bufio" "bufio"
"bytes" "bytes"
"fmt"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
@ -90,4 +90,3 @@ func Clip(x string) {
cmd.Stdin = b cmd.Stdin = b
cmd.Run() cmd.Run()
} }

View File

@ -1,4 +1,4 @@
package gpass package passgo
import ( import (
"bufio" "bufio"
@ -212,4 +212,3 @@ func (s *Store) Decrypt(name string, prompts ...func() []byte) (string,error) {
} }
return string(ra), nil return string(ra), nil
} }