flag.PrintDefaults 包括 `-test` 标志

huangapple go评论85阅读模式
英文:

flag.PrintDefaults includes `-test` flags

问题

我正在使用Go构建一个CLI应用程序。

flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint")
flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds")
flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection")
flag.BoolVar(&verbose, "v", false, "Verbose output")

flag.Usage = func() {
	fmt.Println(`....`)
	fmt.Println("Flags:")
	flag.PrintDefaults()
}

flag.Parse()

if flag.NArg() == 0 {
	flag.Usage()
	os.Exit(1)
}

由于某种奇怪的原因,上面的代码片段会产生以下输出:

Flags:

-T int
        Exit after the specified amount of time in seconds (default 10)
  -c int
        Connections to keep open per endpoint (default 1)
  -r int
        Txs per second to send in a connection (default 1000)
  -test.bench regexp
        run only benchmarks matching regexp
  -test.benchmem
        print memory allocations for benchmarks
  -test.benchtime d
        run each benchmark for duration d (default 1s)
  -test.blockprofile file
        write a goroutine blocking profile to file
  -test.blockprofilerate rate
        set blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
  -test.count n
        run tests and benchmarks n times (default 1)
  -test.coverprofile file
        write a coverage profile to file
  -test.cpu list
        comma-separated list of cpu counts to run each test with
  -test.cpuprofile file
        write a cpu profile to file
  -test.memprofile file
        write a memory profile to file
  -test.memprofilerate rate
        set memory profiling rate (see runtime.MemProfileRate)
  -test.mutexprofile string
        write a mutex contention profile to the named file after execution
  -test.mutexprofilefraction int
        if >= 0, calls runtime.SetMutexProfileFraction() (default 1)
  -test.outputdir dir
        write profiles to dir
  -test.parallel n
        run at most n tests in parallel (default 2)
  -test.run regexp
        run only tests and examples matching regexp
  -test.short
        run smaller test suite to save time
  -test.timeout d
        fail test binary execution after duration d (0 means unlimited)
  -test.trace file
        write an execution trace to file
  -test.v
        verbose: print additional output
  -v    Verbose output

你有什么想法为什么Go会包含-test标志吗?谢谢!

英文:

I am building a CLI application in Go.

flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint")
flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds")
flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection")
flag.BoolVar(&verbose, "v", false, "Verbose output")

flag.Usage = func() {
	fmt.Println(`....`)
	fmt.Println("Flags:")
	flag.PrintDefaults()
}

flag.Parse()

if flag.NArg() == 0 {
	flag.Usage()
	os.Exit(1)
}

(Full listing on Github)

For some strange reason, the above snippet produces:

Flags:


-T int
        Exit after the specified amount of time in seconds (default 10)
  -c int
        Connections to keep open per endpoint (default 1)
  -r int
        Txs per second to send in a connection (default 1000)
  -test.bench regexp
        run only benchmarks matching regexp
  -test.benchmem
        print memory allocations for benchmarks
  -test.benchtime d
        run each benchmark for duration d (default 1s)
  -test.blockprofile file
        write a goroutine blocking profile to file
  -test.blockprofilerate rate
        set blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
  -test.count n
        run tests and benchmarks n times (default 1)
  -test.coverprofile file
        write a coverage profile to file
  -test.cpu list
        comma-separated list of cpu counts to run each test with
  -test.cpuprofile file
        write a cpu profile to file
  -test.memprofile file
        write a memory profile to file
  -test.memprofilerate rate
        set memory profiling rate (see runtime.MemProfileRate)
  -test.mutexprofile string
        write a mutex contention profile to the named file after execution
  -test.mutexprofilefraction int
        if >= 0, calls runtime.SetMutexProfileFraction() (default 1)
  -test.outputdir dir
        write profiles to dir
  -test.parallel n
        run at most n tests in parallel (default 2)
  -test.run regexp
        run only tests and examples matching regexp
  -test.short
        run smaller test suite to save time
  -test.timeout d
        fail test binary execution after duration d (0 means unlimited)
  -test.trace file
        write an execution trace to file
  -test.v
        verbose: print additional output
  -v    Verbose output

Any ideas why Go includes -test flags? Thanks!

答案1

得分: 1

我看到你的代码中有很多依赖项。我发现github.com/tendermint/tmlibs/log库依赖于标准库中的testing包:搜索 testing。而这个标准库中包含了你所关心的所有标志:testing 包

英文:

As I can see you have a bunch f dependencies in your code. I have found that library github.com/tendermint/tmlibs/log has a dependency to a package testing from standard library: searches for testing. And this standard library has all flags you are wondered about: testing package

huangapple
  • 本文由 发表于 2017年7月30日 00:43:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/45391686.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定