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 關注
- 107 瀏覽
添加回答
舉報