golang标志默认打印的隐藏选项

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) -l n skip first n lines of input -t N run N attempts in parallel threads (default 50)

i want hide from printdefaults -l and -t, how i can do this ?

There might be multiple ways of doing this. An easy one would be to use 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.


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