lockbox

password manager
Log | Files | Refs | README | LICENSE

commit a34be9975bbb7b2f0396626748f3ac10901fd68a
parent 9b19a35e05b70d9e46b3cc122f60542206e503c7
Author: Sean Enck <sean@ttypty.com>
Date:   Sat,  4 Mar 2023 16:06:29 -0500

pgl update

Diffstat:
Mcmd/main.go | 4++--
Mgo.mod | 3++-
Mgo.sum | 6++++--
Minternal/app/core.go | 4++--
Minternal/inputs/stdin.go | 10++++++++--
Dinternal/util/core.go | 75---------------------------------------------------------------------------
Mscripts/testing/check.go | 14+++++---------
7 files changed, 23 insertions(+), 93 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -15,7 +15,7 @@ import ( "github.com/enckse/lockbox/internal/inputs" "github.com/enckse/lockbox/internal/platform" "github.com/enckse/lockbox/internal/totp" - "github.com/enckse/lockbox/internal/util" + o "github.com/enckse/pgl/os" ) //go:embed "vers.txt" @@ -23,7 +23,7 @@ var version string func main() { if err := run(); err != nil { - util.Die(err) + o.Die(err) } } diff --git a/go.mod b/go.mod @@ -13,6 +13,7 @@ require ( github.com/aead/argon2 v0.0.0-20180111183520-a87724528b07 // indirect github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect github.com/boombuler/barcode v1.0.1 // indirect + github.com/enckse/pgl v0.0.0-20230304205932-b43af79e9244 // indirect golang.org/x/crypto v0.6.0 // indirect - golang.org/x/sys v0.5.0 // indirect + golang.org/x/sys v0.6.0 // indirect ) diff --git a/go.sum b/go.sum @@ -9,6 +9,8 @@ github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyX github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/enckse/pgl v0.0.0-20230304205932-b43af79e9244 h1:VqBkM9eBABWwHkiBdyafBDwH+vhHDU1OPb4zUkrXiGk= +github.com/enckse/pgl v0.0.0-20230304205932-b43af79e9244/go.mod h1:r5bqGzwqnJIeY6UbGT5u38keJ5+ZySlsWeaYYzdBhMg= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -26,8 +28,8 @@ github.com/tobischo/gokeepasslib/v3 v3.5.0/go.mod h1:IFUgenONAqJlU2RLfVagQbF4GRY golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/exp v0.0.0-20230105202349-8879d0199aa3 h1:fJwx88sMf5RXwDwziL0/Mn9Wqs+efMSo/RYcL+37W9c= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= mvdan.cc/sh/v3 v3.6.0 h1:gtva4EXJ0dFNvl5bHjcUEvws+KRcDslT8VKheTYkbGU= mvdan.cc/sh/v3 v3.6.0/go.mod h1:U4mhtBLZ32iWhif5/lD+ygy1zrgaQhUu+XFy7C8+TTA= diff --git a/internal/app/core.go b/internal/app/core.go @@ -7,7 +7,7 @@ import ( "github.com/enckse/lockbox/internal/backend" "github.com/enckse/lockbox/internal/inputs" - "github.com/enckse/lockbox/internal/util" + o "github.com/enckse/pgl/os" ) type ( @@ -54,7 +54,7 @@ func (a *DefaultCommand) Transaction() *backend.Transaction { func (a *DefaultCommand) Confirm(prompt string) bool { yesNo, err := inputs.ConfirmYesNoPrompt(prompt) if err != nil { - util.Dief("failed to read stdin for confirmation: %v", err) + o.Dief("failed to read stdin for confirmation: %v", err) } return yesNo } diff --git a/internal/inputs/stdin.go b/internal/inputs/stdin.go @@ -8,7 +8,7 @@ import ( "strings" "syscall" - "github.com/enckse/lockbox/internal/util" + "github.com/enckse/pgl/io" ) func termEcho(on bool) { @@ -86,7 +86,13 @@ func confirmInputsMatch() (string, error) { // Stdin will get one (or more) lines of stdin as string. func Stdin(one bool) (string, error) { - b, err := util.ReadStdin(one) + var b []byte + var err error + if one { + b, err = io.ReadStdinLine() + } else { + b, err = io.ReadAllStdin() + } if err != nil { return "", err } diff --git a/internal/util/core.go b/internal/util/core.go @@ -1,75 +0,0 @@ -// Package util provides some common operations -package util - -import ( - "bufio" - "bytes" - "errors" - "fmt" - "io/fs" - "os" -) - -// PathExists will indicate if a path exists -func PathExists(file string) bool { - if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) { - return false - } - return true -} - -// Dief will for a message and die -func Dief(format string, a ...any) { - Die(fmt.Sprintf(format, a...)) -} - -// Die will write to stderr and exit (1) -func Die(a any) { - if a != nil { - fmt.Fprintf(os.Stderr, "%v\n", a) - } - os.Exit(1) -} - -// Copy will copy a file from source to destination via ReadFile/WriteFile -func Copy(src, dst string, mode fs.FileMode) error { - if !PathExists(src) { - return fmt.Errorf("source file '%s' does not exist", src) - } - - in, err := os.ReadFile(src) - if err != nil { - return err - } - - if err := os.WriteFile(dst, in, mode); err != nil { - return err - } - - return nil -} - -// ReadStdin will read one (or more) stdin lines -func ReadStdin(one bool) ([]byte, error) { - scanner := bufio.NewScanner(os.Stdin) - var b bytes.Buffer - for scanner.Scan() { - b.WriteString(scanner.Text()) - b.WriteString("\n") - if one { - break - } - } - if err := scanner.Err(); err != nil { - return nil, err - } - return b.Bytes(), nil -} - -// IfNotSet will return the value or the default if the value is the value's default setting -func IfNotSet[T comparable](val, defaultTo T) T { - if val == *new(T) { - return defaultTo - } - return val -} diff --git a/scripts/testing/check.go b/scripts/testing/check.go @@ -12,7 +12,8 @@ import ( "strings" "time" - "github.com/enckse/lockbox/internal/util" + fp "github.com/enckse/pgl/filepath" + o "github.com/enckse/pgl/os" ) var yes = []string{"y"} @@ -21,17 +22,12 @@ const ( testKey = "plaintextkey" ) -func die(message string, err error) { - fmt.Fprintf(os.Stderr, "%s (%v)", message, err) - os.Exit(1) -} - func runCommand(args []string, data []string) { p := exec.Command(os.Getenv("LB_BUILD"), args...) var buf bytes.Buffer for _, d := range data { if _, err := buf.WriteString(fmt.Sprintf("%s\n", d)); err != nil { - die("failed to write stdin", err) + o.Dief("failed to write stdin: %v", err) } } p.Stdout = os.Stdout @@ -64,7 +60,7 @@ func totpList() { func main() { if err := execute(); err != nil { - die("execution failed", err) + o.Die(err) } } @@ -215,7 +211,7 @@ func testClipboard(dataPath string, tries uint, wait uint) { } foundClipCount := 0 for _, f := range clipFiles { - if util.PathExists(f) { + if fp.PathExists(f) { foundClipCount++ } }