Skip to content

Goのflagパッケージで最高のusageを出力する方法

This content is a draft and will not be included in production builds.

Goのflagパッケージが-optになっている理由

ゼロ値でなければデフォルト値を出力できる。

flag.Var(&overwriteFields, "replace", "field-value expression")
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintln(w, "usage:", progname, "[options] [file ...]")
fmt.Fprintln(w, "\noptions:")
flag.PrintDefaults()
}
flag.Parse()