forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
68 lines (55 loc) · 1.77 KB
/
context.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
package main
import (
"context"
"os"
"runtime"
"golang.org/x/crypto/ssh/terminal"
"github.com/gopasspw/gopass/pkg/backend/crypto/gpg"
"github.com/gopasspw/gopass/pkg/config"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/store/sub"
"github.com/fatih/color"
)
func initContext(ctx context.Context, cfg *config.Config) context.Context {
// always trust
ctx = gpg.WithAlwaysTrust(ctx, true)
// check recipients conflicts with always trust, make sure it's not enabled
// when always trust is
if gpg.IsAlwaysTrust(ctx) {
ctx = sub.WithCheckRecipients(ctx, false)
}
// debug flag
if gdb := os.Getenv("GOPASS_DEBUG"); gdb == "true" {
ctx = ctxutil.WithDebug(ctx, true)
}
// need this override for our integration tests
if nc := os.Getenv("GOPASS_NOCOLOR"); nc == "true" || ctxutil.IsNoColor(ctx) {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
}
// support for no-color.org
if nc := os.Getenv("NO_COLOR"); nc != "" {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
}
// only emit color codes when stdout is a terminal
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
ctx = ctxutil.WithTerminal(ctx, false)
ctx = ctxutil.WithInteractive(ctx, false)
}
// reading from stdin?
if info, err := os.Stdin.Stat(); err == nil && info.Mode()&os.ModeCharDevice == 0 {
ctx = ctxutil.WithInteractive(ctx, false)
ctx = ctxutil.WithStdin(ctx, true)
}
// disable colored output on windows since cmd.exe doesn't support ANSI color
// codes. Other terminal may do, but until we can figure that out better
// disable this for all terms on this platform
if runtime.GOOS == "windows" {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
}
return ctx
}