-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathflags.go
More file actions
78 lines (69 loc) · 2.33 KB
/
flags.go
File metadata and controls
78 lines (69 loc) · 2.33 KB
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
package api
import (
"flag"
"os"
)
// Flags encapsulates the standard flags that should be added to all commands
// that issue API requests.
type Flags struct {
dump *bool
getCurl *bool
trace *bool
insecureSkipVerify *bool
userAgentTelemetry *bool
}
func (f *Flags) Trace() bool {
if f.trace == nil {
return false
}
return *(f.trace)
}
func (f *Flags) GetCurl() bool {
if f.getCurl == nil {
return false
}
return *(f.getCurl)
}
func (f *Flags) UserAgentTelemetry() bool {
if f.userAgentTelemetry == nil {
return defaultUserAgentTelemetry()
}
return *(f.userAgentTelemetry)
}
// NewFlags instantiates a new Flags structure and attaches flags to the given
// flag set.
func NewFlags(flagSet *flag.FlagSet) *Flags {
return &Flags{
dump: flagSet.Bool("dump-requests", false, "Log GraphQL requests and responses to stdout"),
getCurl: flagSet.Bool("get-curl", false, "Print the curl command for executing this query and exit (WARNING: includes printing your access token!)"),
trace: flagSet.Bool("trace", false, "Log the trace ID for requests. See https://docs.sourcegraph.com/admin/observability/tracing"),
insecureSkipVerify: flagSet.Bool("insecure-skip-verify", false, "Skip validation of TLS certificates against trusted chains"),
userAgentTelemetry: flagSet.Bool("user-agent-telemetry", defaultUserAgentTelemetry(), "Include the operating system and architecture in the User-Agent sent with requests to Sourcegraph"),
}
}
// NewFlagsFromValues instantiates a new Flags structure from explicit values.
// This is used by cli/v3 compatibility adapters that do not operate on a
// standard flag.FlagSet.
func NewFlagsFromValues(dump, getCurl, trace, insecureSkipVerify, userAgentTelemetry bool) *Flags {
return &Flags{
dump: new(dump),
getCurl: new(getCurl),
trace: new(trace),
insecureSkipVerify: new(insecureSkipVerify),
userAgentTelemetry: new(userAgentTelemetry),
}
}
func defaultFlags() *Flags {
telemetry := defaultUserAgentTelemetry()
d := false
return &Flags{
dump: &d,
getCurl: &d,
trace: &d,
insecureSkipVerify: &d,
userAgentTelemetry: &telemetry,
}
}
func defaultUserAgentTelemetry() bool {
return os.Getenv("SRC_DISABLE_USER_AGENT_TELEMETRY") == ""
}