Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aviau/gopass
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.5.0
Choose a base ref
...
head repository: aviau/gopass
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Oct 11, 2021

  1. edit: simpler implementation

    aviau committed Oct 11, 2021
    Copy the full SHA
    a38a482 View commit details
  2. README: we support --username

    aviau committed Oct 11, 2021
    Copy the full SHA
    5892b42 View commit details
  3. Copy the full SHA
    52f97e2 View commit details
  4. Copy the full SHA
    0b32196 View commit details
  5. Copy the full SHA
    4421ec8 View commit details
  6. test: use t.TempDir()

    aviau committed Oct 11, 2021
    Copy the full SHA
    4b36490 View commit details
  7. Copy the full SHA
    26fee60 View commit details
  8. ci: run tests (#25)

    aviau authored Oct 11, 2021
    Copy the full SHA
    c6b94bc View commit details
  9. create better CLI test (#24)

    aviau authored Oct 11, 2021
    Copy the full SHA
    5841551 View commit details

Commits on Oct 12, 2021

  1. Copy the full SHA
    0c0555c View commit details
  2. Copy the full SHA
    983ac78 View commit details

Commits on Oct 13, 2021

  1. cli: test --2fa flag (#26)

    aviau authored Oct 13, 2021
    Copy the full SHA
    08e1ede View commit details
  2. Copy the full SHA
    a8e1fa7 View commit details

Commits on Oct 15, 2021

  1. gopasstest -> storetest

    aviau committed Oct 15, 2021
    Copy the full SHA
    8b6ac76 View commit details
  2. cli_test -> clitest

    aviau committed Oct 15, 2021
    Copy the full SHA
    18c3e3a View commit details
  3. clitest: create RunOption

    aviau committed Oct 15, 2021
    Copy the full SHA
    b0734e4 View commit details

Commits on Oct 18, 2021

  1. clitest: create WithFixedTime

    aviau committed Oct 18, 2021
    Copy the full SHA
    15bf078 View commit details
  2. clitest: create RunOptions

    aviau committed Oct 18, 2021
    Copy the full SHA
    d96adef View commit details
  3. Copy the full SHA
    53b5c63 View commit details
  4. run_options: add comments

    aviau committed Oct 18, 2021
    Copy the full SHA
    c8f2f5e View commit details

Commits on Jan 30, 2022

  1. storetest: don't use long paths

    aviau committed Jan 30, 2022
    Copy the full SHA
    b208b7f View commit details
  2. run tests on macos (#28)

    aviau authored Jan 30, 2022
    Copy the full SHA
    8f69862 View commit details
  3. Copy the full SHA
    de3508b View commit details
  4. result -> UID

    aviau committed Jan 30, 2022
    Copy the full SHA
    cf59810 View commit details

Commits on Apr 3, 2022

  1. typo: createa -> create

    aviau authored Apr 3, 2022
    Copy the full SHA
    19a1088 View commit details

Commits on Nov 19, 2022

  1. update deps

    aviau committed Nov 19, 2022
    Copy the full SHA
    8324acb View commit details
  2. update deps

    aviau committed Nov 19, 2022
    Copy the full SHA
    e7848a2 View commit details
Showing with 1,160 additions and 411 deletions.
  1. +6 −3 .github/workflows/{tests-lint.yaml → tests.yaml}
  2. +1 −3 README.md
  3. +17 −6 go.mod
  4. +19 −11 go.sum
  5. +30 −0 internal/alfred/filter.go
  6. +2 −0 internal/cli/cli.go
  7. +41 −25 internal/cli/{cli_test.go → clitest/clitest.go}
  8. +68 −0 internal/cli/clitest/command_config.go
  9. +48 −0 internal/cli/clitest/run_options.go
  10. +106 −0 internal/cli/cmd_alfred.go
  11. +98 −0 internal/cli/cmd_alfred_test.go
  12. 0 internal/cli/{cp.go → cmd_cp.go}
  13. +10 −9 internal/cli/{cp_test.go → cmd_cp_test.go}
  14. +10 −21 internal/cli/{edit.go → cmd_edit.go}
  15. +10 −9 internal/cli/{edit_test.go → cmd_edit_test.go}
  16. 0 internal/cli/{find.go → cmd_find.go}
  17. +10 −9 internal/cli/{find_test.go → cmd_find_test.go}
  18. 0 internal/cli/{generate.go → cmd_generate.go}
  19. +10 −9 internal/cli/{generate_test.go → cmd_generate_test.go}
  20. 0 internal/cli/{git.go → cmd_git.go}
  21. 0 internal/cli/{grep.go → cmd_grep.go}
  22. 0 internal/cli/{help.go → cmd_help.go}
  23. +20 −19 internal/cli/{help_test.go → cmd_help_test.go}
  24. 0 internal/cli/{init.go → cmd_init.go}
  25. +10 −9 internal/cli/{init_test.go → cmd_init_test.go}
  26. +5 −11 internal/cli/{insert.go → cmd_insert.go}
  27. +81 −0 internal/cli/cmd_insert_test.go
  28. 0 internal/cli/{mv.go → cmd_mv.go}
  29. +10 −9 internal/cli/{mv_test.go → cmd_mv_test.go}
  30. 0 internal/cli/{rm.go → cmd_rm.go}
  31. +14 −13 internal/cli/{rm_test.go → cmd_rm_test.go}
  32. +1 −2 internal/cli/{show.go → cmd_show.go}
  33. +123 −0 internal/cli/cmd_show_test.go
  34. 0 internal/cli/{version.go → cmd_version.go}
  35. +5 −4 internal/cli/{version_test.go → cmd_version_test.go}
  36. +51 −9 internal/cli/command_config.go
  37. +0 −47 internal/cli/insert_test.go
  38. +0 −58 internal/cli/show_test.go
  39. +161 −0 internal/gpg/exec.go
  40. +14 −0 internal/gpg/exec_test.go
  41. +37 −6 internal/{gopasstest/gopasstest.go → storetest/storetest.go}
  42. +81 −0 internal/storetest/testdata/CED3B67C8F1F6CA9.private.key
  43. +37 −80 pkg/store/password_store.go
  44. +3 −3 pkg/store/password_store_contains_directory_test.go
  45. +3 −3 pkg/store/password_store_contains_password_test.go
  46. +3 −3 pkg/store/password_store_copy_password_test.go
  47. +2 −2 pkg/store/password_store_get_password_list_test.go
  48. +1 −8 pkg/store/password_store_init_test.go
  49. +3 −3 pkg/store/password_store_move_password_test.go
  50. +1 −9 pkg/store/password_store_new_test.go
  51. +4 −4 pkg/store/password_store_remove_directory_test.go
  52. +4 −4 pkg/store/password_store_remove_password_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
on: [push, pull_request]
name: "tests/lint"
name: "tests"

jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
platform: [ubuntu-latest]
go-version: [1.17.x]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}

steps:
@@ -28,3 +28,6 @@ jobs:
- name: Lint
run: make lint

- name: tests
run: make test
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -23,8 +23,6 @@ This section was just added so that I could get an idea of where I am at.
- [X] Support ``--path`` option
- [X] Support multiple GPG ids
- [X] Re-encryption functionality
- [ ] Should output: ``Password store initialized for [gpg-id].``
- [ ] ``--clone <url>`` allows to init from an existing repo

### ``gopass insert``

@@ -39,7 +37,7 @@ This section was just added so that I could get an idea of where I am at.
- [X] ``gopass show test.com`` will display the content of test.com.gpg
- [X] ``--clip, -c`` copies the first line to the clipboard
- [ ] ``--clip, -c`` clears after a while
- [ ] ``--password``, and ``--username`` options.
- [X] ``--password``, and ``--username`` options.

Accepted format:
```
23 changes: 17 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
module github.com/aviau/gopass

go 1.15
go 1.17

require (
github.com/boombuler/barcode v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/pquerna/otp v1.3.0
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
github.com/stretchr/testify v1.8.1
golang.org/x/term v0.2.0
honnef.co/go/tools v0.2.1
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/boombuler/barcode v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
30 changes: 19 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.3.0 h1:oJV/SkzR33anKXwQU3Of42rL4wbrffP4uvUf1SvS5Xs=
github.com/pquerna/otp v1.3.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -37,21 +44,20 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -66,5 +72,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.2.1 h1:/EPr//+UMMXwMTkXvCCoaJDq8cpjMO80Ou+L4PDo2mY=
honnef.co/go/tools v0.2.1/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY=
30 changes: 30 additions & 0 deletions internal/alfred/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2022 Alexandre Viau <alexandre@alexandreviau.net>
//
// This file is part of gopass.
//
// gopass is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gopass is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with gopass. If not, see <http://www.gnu.org/licenses/>.

// Package alfred defines structs for Alfred script filters.
package alfred

type Output struct {
Items []*Item `json:"items"`
}

type Item struct {
UID string `json:"uid"`
Title string `json:"title"`
Arg string `json:"arg"`
Subtitle string `json:"subtitle,omitempty"`
}
2 changes: 2 additions & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
@@ -36,6 +36,8 @@ func Run(ctx context.Context, cfg CommandConfig, cmdAndArgs []string) error {
return execInsert(cfg, cmdAndArgs[1:])
case "find", "ls", "search", "list":
return execFind(cfg, cmdAndArgs[1:])
case "alfred":
return execAlfred(cfg, cmdAndArgs[1:])
case "":
return execFind(cfg, cmdAndArgs)
case "grep":
66 changes: 41 additions & 25 deletions internal/cli/cli_test.go → internal/cli/clitest/clitest.go
Original file line number Diff line number Diff line change
@@ -15,57 +15,73 @@
// You should have received a copy of the GNU General Public License
// along with gopass. If not, see <http://www.gnu.org/licenses/>.

package cli
// Package clitest provides utilities for testing the CLI.
package clitest

import (
"bytes"
"context"
"os"
"testing"

"github.com/aviau/gopass/internal/gopasstest"
"github.com/aviau/gopass/internal/cli"
"github.com/aviau/gopass/internal/storetest"
"github.com/aviau/gopass/pkg/store"
)

// testConfig is a fake command.Config, it does not use env variables.
type testConfig struct {
CommandConfig
passwordStoreTest *gopasstest.PasswordStoreTest
}

func (cfg *testConfig) PasswordStore() *store.PasswordStore {
return cfg.passwordStoreTest.PasswordStore
}

// cliTest allows for testing the CLI without a TTY.
type cliTest struct {
OutputWriter bytes.Buffer
ErrorWriter bytes.Buffer
t *testing.T
passwordStoreTest *gopasstest.PasswordStoreTest
passwordStoreTest *storetest.PasswordStoreTest
}

func newCliTest(t *testing.T) *cliTest {
passwordStoreTest := gopasstest.NewPasswordStoreTest(t)
func NewCliTest(t *testing.T) *cliTest {
passwordStoreTest := storetest.NewPasswordStoreTest(t)

cliTest := cliTest{
t: t,
passwordStoreTest: passwordStoreTest,
}

return &cliTest
}

func (cliTest *cliTest) PasswordStore() *store.PasswordStore {
return cliTest.passwordStoreTest.PasswordStore
}

func (cliTest *cliTest) Run(args []string) error {
baseConfig := NewCommandConfig(&cliTest.OutputWriter, &cliTest.ErrorWriter, nil)
type runResult struct {
Stdout *bytes.Buffer
Stderr *bytes.Buffer
}

func (cliTest *cliTest) Run(args []string, runOptionFns ...RunOption) (*runResult, error) {
// Create RunOptions
runOptions := &runOptions{}
for _, fn := range runOptionFns {
fn(runOptions)
}

// Create a testConfig
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}

testConfig := &testCommandConfig{
passwordStore: cliTest.PasswordStore(),
runOptions: runOptions,
writerOutput: stdout,
writerError: stderr,
readerInput: os.Stdin,
}

// Run the command
err := cli.Run(context.TODO(), testConfig, args)

testConfig := testConfig{
CommandConfig: baseConfig,
passwordStoreTest: cliTest.passwordStoreTest,
// Results
runResult := &runResult{
Stdout: stdout,
Stderr: stderr,
}

return Run(context.TODO(), &testConfig, args)
return runResult, err
}

func (cliTest *cliTest) Close() {
68 changes: 68 additions & 0 deletions internal/cli/clitest/command_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (C) 2021 Alexandre Viau <alexandre@alexandreviau.net>
//
// This file is part of gopass.
//
// gopass is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gopass is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with gopass. If not, see <http://www.gnu.org/licenses/>.

package clitest

import (
"io"
"time"

"github.com/aviau/gopass/pkg/store"
)

// testCommandConfig is a CommandConfig for testing.
type testCommandConfig struct {
passwordStore *store.PasswordStore
runOptions *runOptions
writerOutput io.Writer
writerError io.Writer
readerInput io.Reader
}

func (cfg *testCommandConfig) PasswordStore() *store.PasswordStore {
return cfg.passwordStore
}

func (cfg *testCommandConfig) PasswordStoreDir() string {
return cfg.passwordStore.Path
}

func (cfg *testCommandConfig) Edit(content string) (string, error) {
if cfg.runOptions.editFunc != nil {
return cfg.runOptions.editFunc(content)
}
return content, nil
}

func (cfg *testCommandConfig) WriterOutput() io.Writer {
return cfg.writerOutput
}

func (cfg *testCommandConfig) WriterError() io.Writer {
return cfg.writerError
}

func (cfg *testCommandConfig) ReaderInput() io.Reader {
return cfg.readerInput
}

func (cfg *testCommandConfig) Now() time.Time {
if cfg.runOptions.nowFunc != nil {
return cfg.runOptions.nowFunc()
}
return time.Now()
}
Loading