-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
25 lines (22 loc) · 981 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main
import (
"flag"
"fmt"
"log"
"github.com/hauntedness/optiongen"
)
func main() {
typeName := flag.String("type", "", "the type name to generate options on, mandatory")
packagePath := flag.String("package", ".", "the package path to search types")
prefix := flag.String("prefix", "", `specify the variables prefix, default ""`)
postfix := flag.String("postfix", "", `specify the variables postfix, default ""`)
writeFile := flag.String("writeFile", "", `specify which file writes to, default "no file"`)
autoImports := flag.Bool("autoImports", true, "organize imports automatically")
flag.Parse()
if *typeName == "" {
log.Fatal("type name is mandatory: optiongen --type someoption")
}
opts := []optiongen.Option{optiongen.WithPostfix(*postfix), optiongen.WithPrefix(*prefix), optiongen.WithAutoImports(*autoImports), optiongen.WithWriteFile(*writeFile)}
generated := optiongen.ExecuteString(*typeName, *packagePath, opts...)
fmt.Println(generated)
}