forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
44 lines (40 loc) · 996 Bytes
/
debug.go
File metadata and controls
44 lines (40 loc) · 996 Bytes
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
package opts
import (
"os"
"strings"
)
// The SQLCDEBUG variable controls debugging variables within the runtime. It
// is a comma-separated list of name=val pairs setting these named variables:
//
// dumpast: setting dumpast=1 will print the AST of every SQL statement
// dumpcatalog: setting dumpcatalog=1 will print the parsed database schema
// trace: setting trace=<path> will output a trace
type Debug struct {
DumpAST bool
DumpCatalog bool
Trace string
}
func DebugFromEnv() Debug {
d := Debug{}
val := os.Getenv("SQLCDEBUG")
if val == "" {
return d
}
for _, pair := range strings.Split(val, ",") {
pair = strings.TrimSpace(pair)
switch {
case pair == "dumpast=1":
d.DumpAST = true
case pair == "dumpcatalog=1":
d.DumpCatalog = true
case strings.HasPrefix(pair, "trace="):
traceName := strings.TrimPrefix(pair, "trace=")
if traceName == "1" {
d.Trace = "trace.out"
} else {
d.Trace = traceName
}
}
}
return d
}