Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lucor committed Feb 28, 2022
2 parents f2e0b6e + d32c70c commit c7fb21c
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 39 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog - Paw

## 0.16.0 - 28 February 2022

- all: fix regression about setting item date
- cli: add the "-c, --clip" option to copy password to clipboard
- cli: update messages to printed correctly on stdout and stderr
- cli:list command will show an hint message if no vaults are found
- cli,deps: add golang.design/x/clipboard
- gui,deps: update fyne.io/fyne to v2.1.3

## 0.15.0 - 26 January 2022

- cli: add CLI application #3
Expand Down
14 changes: 7 additions & 7 deletions cmd/paw-cli/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"log"
"fmt"
"os"

"lucor.dev/paw/internal/cli"
Expand All @@ -12,12 +12,10 @@ import (
var Version string

func main() {

log.SetFlags(0)

s, err := paw.NewOSStorage()
if err != nil {
log.Fatal(err)
fmt.Fprintf(os.Stderr, "[✗] %s\n", err)
os.Exit(1)
}

// Define the command to use
Expand Down Expand Up @@ -58,12 +56,14 @@ func main() {
// and will exit in case of error
err = cmd.Parse(os.Args[2:])
if err != nil {
log.Fatalf("[✗] %s", err)
fmt.Fprintf(os.Stderr, "[✗] %s\n", err)
os.Exit(1)
}

// Finally run the command
err = cmd.Run(s)
if err != nil {
log.Fatalf("[✗] %s", err)
fmt.Fprintf(os.Stderr, "[✗] %s\n", err)
os.Exit(1)
}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ go 1.16

require (
filippo.io/age v1.0.0
fyne.io/fyne/v2 v2.1.2
fyne.io/fyne/v2 v2.1.3
github.com/stretchr/testify v1.7.0
golang.design/x/clipboard v0.6.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
Expand Down
20 changes: 18 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
filippo.io/age v1.0.0 h1:V6q14n0mqYU3qKFkZ6oOaF9oXneOviS3ubXsSVBRSzc=
filippo.io/age v1.0.0/go.mod h1:PaX+Si/Sd5G8LgfCwldsSba3H1DDQZhIhFGkhbHaBq8=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
fyne.io/fyne/v2 v2.1.2 h1:avp9CvLAUdvE7fDMtH1tVKyjxEWHWcpow6aI6L7Kvvw=
fyne.io/fyne/v2 v2.1.2/go.mod h1:p+E/Dh+wPW8JwR2DVcsZ9iXgR9ZKde80+Y+40Is54AQ=
fyne.io/fyne/v2 v2.1.3 h1:I5qSeENAcq67hmO5Z2hI7sEJm9bdLMDJx59Fv8qJkX0=
fyne.io/fyne/v2 v2.1.3/go.mod h1:p+E/Dh+wPW8JwR2DVcsZ9iXgR9ZKde80+Y+40Is54AQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
Expand Down Expand Up @@ -54,14 +55,27 @@ github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/X
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.3.8 h1:Nw158Q8QN+CPgTmVRByhVwapp8Mm1e2blinhmx4wx5E=
github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.design/x/clipboard v0.6.0 h1:+U/e2KDBdpIjkRdxO8GwlD6dKD3Jx5zlNNzQjxte4A0=
golang.design/x/clipboard v0.6.0/go.mod h1:ep0pB+/4DGJK3ayLxweWJFHhHGGv3npJJHMXAjtLTUM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 h1:3In5TnfvnuXTF/uflgpYxSCEGP2NdYT37KsPh3VjZYU=
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554/go.mod h1:jFTmtFYCV0MFtXBU+J5V/+5AUeVS0ON/0WkE/KSrl6E=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
Expand Down Expand Up @@ -89,7 +103,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
8 changes: 5 additions & 3 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"bufio"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"

"golang.org/x/term"

"lucor.dev/paw/internal/paw"
)

Expand Down Expand Up @@ -47,11 +47,13 @@ func printUsage(textTemplate string, data interface{}) {
func printTemplate(w io.Writer, textTemplate string, data interface{}) {
tpl, err := template.New("tpl").Parse(textTemplate)
if err != nil {
log.Fatalf("Could not parse the template: %s", err)
fmt.Fprintf(os.Stderr, "[✗] could not parse the template: %s\n", err)
os.Exit(1)
}
err = tpl.Execute(w, data)
if err != nil {
log.Fatalf("Could not execute the template: %s", err)
fmt.Fprintf(os.Stderr, "[✗] could not execute the template: %s\n", err)
os.Exit(1)
}
}

Expand Down
49 changes: 49 additions & 0 deletions internal/cli/clipboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cli

import (
"bytes"
"context"
"fmt"
"time"

"golang.design/x/clipboard"
)

const (
clipboardWatchInterval = 10 * time.Millisecond
clipboardWriteTimeout = 1 * time.Second
)

func writeToClipboard(ctx context.Context, data []byte) error {
last := clipboard.Read(clipboard.FmtText)
if bytes.Equal(last, data) {
// data is the same in clipboard no need to write
return nil
}

clipboard.Write(clipboard.FmtText, data)

ti := time.NewTicker(clipboardWatchInterval)
defer ti.Stop()

for {
select {
case <-ctx.Done():
return fmt.Errorf("unable to write data to clipboard: timeout reached")
case <-ti.C:
b := clipboard.Read(clipboard.FmtText)
if b == nil {
continue
}
if bytes.Equal(last, b) {
// clipboard data not changed
continue
}
if !bytes.Equal(b, data) {
// clipboard data changed but with unexpected content
return fmt.Errorf("clipboard has been overwritten by others and data is lost")
}
return nil
}
}
}
3 changes: 1 addition & 2 deletions internal/cli/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"log"
"os"

"lucor.dev/paw/internal/paw"
Expand Down Expand Up @@ -100,7 +99,7 @@ func (cmd *AddCmd) Run(s paw.Storage) error {
if err != nil {
return err
}
log.Printf("[✓] item %q added", cmd.itemName)
fmt.Printf("[✓] item %q added\n", cmd.itemName)
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions internal/cli/cmd_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cli

import (
"fmt"
"log"
"os"
"time"

"lucor.dev/paw/internal/paw"
)
Expand Down Expand Up @@ -89,6 +89,8 @@ func (cmd *EditCmd) Run(s paw.Storage) error {
return fmt.Errorf("unsupported item type: %q", cmd.itemType)
}

item.GetMetadata().Modified = time.Now()

err = s.StoreItem(vault, item)
if err != nil {
return err
Expand All @@ -101,7 +103,7 @@ func (cmd *EditCmd) Run(s paw.Storage) error {
if err != nil {
return err
}
log.Printf("[✓] item %q modified", cmd.itemName)
fmt.Printf("[✓] item %q modified\n", cmd.itemName)
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions internal/cli/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"log"
"os"

"lucor.dev/paw/internal/paw"
Expand Down Expand Up @@ -68,6 +67,6 @@ func (cmd *InitCmd) Run(s paw.Storage) error {
if err != nil {
return err
}
log.Printf("[✓] vault %q created", cmd.vaultName)
fmt.Printf("[✓] vault %q created\n", cmd.vaultName)
return nil
}
6 changes: 4 additions & 2 deletions internal/cli/cmd_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"log"
"os"

"lucor.dev/paw/internal/paw"
Expand Down Expand Up @@ -88,7 +87,7 @@ func (cmd *ListCmd) Run(s paw.Storage) error {
}

if len(n.Child) == 0 {
log.Printf("vault %q is empty", cmd.vaultName)
fmt.Printf("vault %q is empty\n", cmd.vaultName)
return nil
}

Expand Down Expand Up @@ -141,6 +140,9 @@ func (cmd *ListCmd) vaults(s paw.Storage) (tree.Node, error) {
if err != nil {
return n, err
}
if len(vaults) == 0 {
return n, fmt.Errorf("no vaults found. To create one: paw-cli init VAULT")
}
for _, v := range vaults {
if cmd.vaultName != "" && cmd.vaultName != v {
continue
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/cmd_pwgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"log"
"os"

"lucor.dev/paw/internal/paw"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (cmd *PwGenCmd) Run(s paw.Storage) error {
return err
}

log.Println(password.Value)
fmt.Println(password.Value)
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions internal/cli/cmd_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"fmt"
"log"
"os"

"lucor.dev/paw/internal/paw"
Expand Down Expand Up @@ -98,6 +97,6 @@ func (cmd *RemoveCmd) Run(s paw.Storage) error {
return err
}

log.Printf("[✓] item %q removed", cmd.itemName)
fmt.Printf("[✓] item %q removed\n", cmd.itemName)
return nil
}
Loading

0 comments on commit c7fb21c

Please sign in to comment.