-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
64 lines (54 loc) · 1.26 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"github.com/gopasspw/gopass/pkg/gopass/api"
"github.com/urfave/cli/v2"
)
const (
name = "summon-gopass"
)
// Version is the released version of gopass.
var version string
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
defer func() {
signal.Stop(sigChan)
cancel()
}()
go func() {
select {
case <-sigChan:
cancel()
case <-ctx.Done():
}
}()
gp, err := api.New(ctx)
if err != nil {
fmt.Printf("Failed to initialize gopass API: %s\n", err)
os.Exit(1)
}
gc := &gc{
gp: gp,
}
app := cli.NewApp()
app.Name = name
app.Version = getVersion().String()
app.Usage = `Use "gopass-summon-provider" as provider for "summon"`
app.Description = "" +
"This command allows to use gopass as a secret provider for summon." +
"To use it set the 'SUMMON_PROVIDER' variable to this executable or" +
"copy or link it (as `gopass`) into the summon provider directory" +
"'/usr/local/lib/summon/'. See 'summon' documentation for more details."
app.Action = gc.Get
if err := app.RunContext(ctx, os.Args); err != nil {
log.Fatal(err)
}
}