【问题标题】:flag.PrintDefaults includes `-test` flagsflag.PrintDefaults 包括 `-test` 标志
【发布时间】:2017-07-30 05:38:42
【问题描述】:

我正在用 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)
}

(Full listing on Github)

由于某种奇怪的原因,上面的 sn-p 产生了:

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 标志吗?谢谢!

【问题讨论】:

  • 您正在导入“测试”包。
  • github.com/tendermint/tools/blob/develop/tm-bench/main.go 不这么认为......但看起来测试包确实把事情搞砸了
  • 构建二进制文件的确切命令行是什么?
  • 我正在使用go build
  • 程序间接导入github.com/tendermint/tmlibs/log,后者导入testing包。想办法打破对testing 包的依赖。

标签: go command-line


【解决方案1】:

我可以看到你的代码中有一堆 f 依赖项。我发现库github.com/tendermint/tmlibs/log 依赖于来自标准库的包testingsearches for testing。这个标准库有你想知道的所有标志:testing package

【讨论】:

    猜你喜欢
    • 2014-02-06
    • 2013-06-12
    • 2020-01-25
    • 2013-05-31
    • 2018-08-25
    • 2021-10-19
    • 1970-01-01
    • 2016-07-01
    • 2018-05-04
    相关资源
    最近更新 更多