[英]golang flag hidden options from print defaults
this is my actual code : 这是我的实际代码:
package main
import (
"flag"
)
var loadList = ""
var threads = 50
var skip = 0
func main() {
//defaults variables
flag.StringVar(&loadList, "f", "", "load links list file (required)")
flag.IntVar(&threads,"t", 50, "run `N` attempts in parallel threads")
flag.IntVar(&skip, "l", 0, "skip first `n` lines of input")
flag.Parse()
flag.PrintDefaults()
}
and this is output : 这是输出:
-f string load links list file (required) -ln skip first n lines of input -t N run N attempts in parallel threads (default 50) -f字符串装入链接列表文件(必需)-ln跳过输入的前n行-t N在并行线程中运行N次尝试(默认值为50)
i want hide from printdefaults -l and -t, how i can do this ? 我想从printdefaults -l和-t隐藏,我该怎么做?
There might be multiple ways of doing this. 可能有多种方法可以做到这一点。 An easy one would be to use VisitAll
: 一种简单的方法是使用VisitAll
:
func VisitAll(fn func(*Flag))
In the function you pass you can decide whether or not to output a flag based on any of the exported fields of Flag
. 在传递的函数中,您可以根据Flag
任何导出字段来决定是否输出Flag
。
Example: 例:
flag.VisitAll(func(f *flag.Flag) {
if f.Name == "l" || f.Name == "t" {
return
}
fmt.Println("Flag: ", f)
})
Run it at: https://play.golang.org/p/rsrKgWeAQf 在以下位置运行它: https : //play.golang.org/p/rsrKgWeAQf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.