/
flag.go
97 lines (79 loc) · 1.99 KB
/
flag.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright(C) 2023 github.com/fsgo All Rights Reserved.
// Author: hidu <duv123@gmail.com>
// Date: 2023/4/13
package zpass
import (
"flag"
"fmt"
"os"
"strings"
"sync"
"github.com/fsgo/fsgo/fssync/fsatomic"
"github.com/fsgo/gocode/internal/xflag"
)
var debug fsatomic.String
var parserOnce sync.Once
var vv = flag.Bool("vv", false, "show verbose trace logs")
func tryParserFlags() {
parserOnce.Do(func() {
flag.Parse()
if ft := flag.Lookup("debug"); ft != nil {
debug.Store(ft.Value.String())
}
})
}
// IsDebug 判断是否指定 debug 类型
// Debug is a set of single-letter flags:
//
// f show [f]acts as they are created
// p disable [p]arallel execution of analyzers
// s do additional [s]anity checks on fact types and serialization
// t show [t]iming info (NB: use 'p' flag to avoid GC/scheduler noise)
// v show [v]erbose logging
func IsDebug(s string) bool {
return strings.Contains(debug.Load(), s)
}
// IsDebugVerbose show verbose logging
func IsDebugVerbose() bool {
return IsDebug("v")
}
// IsTrace verbose trace logs
func IsTrace() bool {
return *vv
}
// IsDebugTiming show timing info
func IsDebugTiming() bool {
return IsDebug("t")
}
// IsDebugFacts how facts as they are created
func IsDebugFacts() bool {
return IsDebug("f")
}
// IsDebugParallel disable parallel execution of analyzers
func IsDebugParallel() bool {
return IsDebug("p")
}
// IsDebugSanity do additional sanity checks on fact types and serialization
func IsDebugSanity() bool {
return IsDebug("s")
}
func init() {
flag.CommandLine.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
xflag.PrintDefaults(flag.CommandLine, func(g *flag.Flag, usage string) bool {
if strings.Contains(usage, "deprecated") {
return true
}
if _, ok := flagIgnoreName.Load(g.Name); ok {
return true
}
return false
})
}
}
var flagIgnoreName sync.Map
func AddIgnoreFlagName(names ...string) {
for _, name := range names {
flagIgnoreName.Store(name, true)
}
}