2021-10-30 21:47:47 +00:00
|
|
|
//go:build generate
|
|
|
|
// +build generate
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.jolheiser.com/ffmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:generate go run main.go
|
|
|
|
func main() {
|
|
|
|
fs := flag.NewFlagSet("myapp", flag.ExitOnError)
|
|
|
|
fs.String("string-flag", "", "String flag with no default")
|
|
|
|
fs.String("string-flag-default", "string default", "String flag with default")
|
|
|
|
fs.Int("int-flag", 0, "Int flag with no default")
|
|
|
|
fs.Int("int-flag-default", 100, "Int flag with default")
|
|
|
|
fs.Bool("bool-flag-f", false, "Bool flag false")
|
|
|
|
fs.Bool("bool-flag-t", true, "Bool flag true")
|
|
|
|
fs.Duration("duration-flag", 0, "Duration flag with no default")
|
|
|
|
fs.Duration("duration-flag-default", time.Minute*5, "Duration flag with default")
|
|
|
|
|
2021-10-31 21:04:40 +00:00
|
|
|
md, err := ffmd.FlagSet(fs)
|
2021-10-30 21:47:47 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-30 21:52:53 +00:00
|
|
|
write("README.md", md)
|
2021-10-30 21:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func write(path, content string) {
|
|
|
|
fi, err := os.Create(path)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer fi.Close()
|
|
|
|
if _, err := fi.WriteString(content); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|