1 回答

TA贡献1719条经验 获得超6个赞
value
是flag.UnquoteUsage
为自定义类型(通过 呈现flag.(*FlagSet).PrintDefaults
)选择的默认参数名称。
您可以在使用文本中使用反引号覆盖默认值。反引号从使用文本中删除。例如:
package main
import (
"flag"
"fmt"
)
type stringSlice []string
func (s *stringSlice) String() string {
return fmt.Sprint(*s)
}
func (s *stringSlice) Set(v string) error {
*s = append(*s, v)
return nil
}
func main() {
var s stringSlice
flag.Var(&s, "foo", "append a foo to the list")
flag.Var(&s, "foo2", "append a `foo` to the list")
flag.Parse()
}
运行 with-h显示参数名称如何变化:
Usage of ./flagusage:
-foo value
append a foo to the list
-foo2 foo
append a foo to the list
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报