forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
80 lines (66 loc) · 1.89 KB
/
app.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"os"
"strings"
ap "github.com/gopasspw/gopass/pkg/action"
"github.com/gopasspw/gopass/pkg/config"
"github.com/gopasspw/gopass/pkg/out"
"github.com/gopasspw/gopass/pkg/store/sub"
"github.com/gopasspw/gopass/pkg/termio"
"github.com/blang/semver"
"github.com/urfave/cli"
)
func setupApp(ctx context.Context, sv semver.Version) *cli.App {
// try to read config (if it exists)
cfg := config.Load()
// set config values
ctx = initContext(ctx, cfg)
// initialize action handlers
action, err := ap.New(ctx, cfg, sv)
if err != nil {
out.Error(ctx, "No gpg binary found: %s", err)
os.Exit(ap.ExitGPG)
}
// set some action callbacks
if !cfg.Root.AutoImport {
ctx = sub.WithImportFunc(ctx, termio.AskForKeyImport)
}
if !cfg.Root.NoConfirm {
ctx = sub.WithRecipientFunc(ctx, action.ConfirmRecipients)
}
ctx = sub.WithFsckFunc(ctx, termio.AskForConfirmation)
app := cli.NewApp()
app.Name = name
app.Version = sv.String()
app.Usage = "The standard unix password manager - rewritten in Go"
app.EnableBashCompletion = true
app.BashComplete = func(c *cli.Context) {
cli.DefaultAppComplete(c)
action.Complete(ctx, c)
}
app.Action = func(c *cli.Context) error {
if err := action.Initialized(withGlobalFlags(ctx, c), c); err != nil {
return err
}
if strings.HasSuffix(os.Args[0], "native_host") || strings.HasSuffix(os.Args[0], "native_host.exe") {
return action.JSONAPI(withGlobalFlags(ctx, c), c)
}
if c.Args().Present() {
return action.Show(withGlobalFlags(ctx, c), c)
}
return action.List(withGlobalFlags(ctx, c), c)
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "yes",
Usage: "Assume yes on all yes/no questions or use the default on all others",
},
cli.BoolFlag{
Name: "clip, c",
Usage: "Copy the first line of the secret into the clipboard",
},
}
app.Commands = getCommands(ctx, action, app)
return app
}