45 lines
980 B
Go
45 lines
980 B
Go
//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")
|
|
|
|
md, err := ffmd.FlagSet(fs)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
write("README.md", md)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|