complete/compflag/gen/main.go

41 lines
717 B
Go
Raw Normal View History

2020-05-09 05:36:38 -05:00
// Generates flags.go.
package main
import (
"log"
"strings"
2020-05-09 22:04:42 -05:00
"github.com/posener/autogen"
2020-05-09 05:36:38 -05:00
)
2020-05-09 22:04:42 -05:00
//go:generate go run .
2020-05-09 05:36:38 -05:00
type flag struct {
Name string
Type string
IsBool bool
CustomPredict bool
}
func (f flag) NewInternalTypeFuncName() string {
return "new" + strings.Title(f.InternalTypeName())
}
func (f flag) InternalTypeName() string {
return strings.ToLower(f.Name[:1]) + f.Name[1:] + "Value"
}
var flags = []flag{
{Name: "String", Type: "string"},
{Name: "Bool", Type: "bool", IsBool: true, CustomPredict: true},
{Name: "Int", Type: "int"},
{Name: "Duration", Type: "time.Duration"},
}
func main() {
2020-05-09 22:04:42 -05:00
err := autogen.Execute(flags)
if err != nil {
log.Fatal(err)
2020-05-09 05:36:38 -05:00
}
}