forked from gopasspw/gopass-jsonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonapi.go
38 lines (30 loc) · 753 Bytes
/
jsonapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"os"
"strings"
"github.com/blang/semver"
"github.com/gopasspw/gopass-jsonapi/internal/jsonapi"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/gopass"
"github.com/urfave/cli/v2"
)
var (
stdin = os.Stdin
stdout = os.Stdout
)
type jsonapiCLI struct {
gp gopass.Store
}
// listen reads a json message on stdin and responds on stdout.
func (s *jsonapiCLI) listen(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
version, err := semver.Parse(strings.TrimPrefix(c.App.Version, "v"))
if err != nil {
version = semver.Version{}
}
api := jsonapi.New(s.gp, stdin, stdout, version)
if err := api.ServeMessage(ctx); err != nil {
return api.SendErrorResponse(err)
}
return nil
}