我有一个项目使用包标志来读取 argv(参数),当没有给出参数时它会打印默认设置:
func initFlag() {
path := flag.String("F", "store_server.conf", "config file path")
v := flag.Bool("V", false, "print version")
flag.Parse()
if flag.NFlag() == 0 {
flag.PrintDefaults()
os.Exit(0)
}
fmt.Println(*path, *v)
}
func main() {
initFlag() // initialize flag and load configure file
select{}
}
执行结果如下:
vinllen@ ~$ go run main.go
-F string
config file path (default "store_server.conf")
-V print version
但是当我的代码包含其他包时glog
,该PrintDefaults
函数将显示更多设置,包括glog
标志:
-F string
config file path (default "store_server.conf")
-V print version
-alsologtostderr
log to standard error as well as files
-log_backtrace_at value
when logging hits line file:N, emit a stack trace
-log_dir string
If non-empty, write log files in this directory
-logtostderr
log to standard error instead of files
-stderrthreshold value
logs at or above this threshold go to stderr
-v value
log level for V logs
-vmodule value
comma-separated list of pattern=N settings for file-filtered logging
我需要的唯一两个设置是-F
和-V
,如何删除其他设置?