Skip to content

Commit acdf99c

Browse files
committed
- [+] commandlineFlag now deal with bool variables
1 parent 72f2ee9 commit acdf99c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

test/commandlineFlag.ref

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ func init() {
5656
flag.IntVar(&Opts.Debug, "debug", 0,
5757
"debugging `level`")
5858

59+
exists := false
5960
// Now override those default values from environment variables
61+
if _, exists = os.LookupEnv("EASYGEN_HTML"); Opts.HTML|| exists {
62+
Opts.HTML = true
63+
}
6064
if len(Opts.TemplateStr) == 0 ||
6165
len(os.Getenv("EASYGEN_TS")) != 0 {
6266
Opts.TemplateStr = os.Getenv("EASYGEN_TS")

test/commandlineFlag.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ func init() {
3737
flag.{{clk2uc .Type}}Var(&{{$.StructVar}}.{{.Name}}, "{{.Flag}}", {{.Value}},
3838
"{{.Usage}}"){{end}}{{end}}
3939

40+
exists := false
4041
// Now override those default values from environment variables{{range .Options}}{{if eq .Name "SEPARATOR" }}
4142

42-
{{else}}{{if eq .Type "string" }}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .Flag)}}
43+
{{else}}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .Flag)}}{{if eq .Type "string" }}
4344
if len({{$.StructVar}}.{{.Name}}) == 0 ||
4445
len(os.Getenv("{{$envVar}}")) != 0 {
4546
{{$.StructVar}}.{{.Name}} = os.Getenv("{{$envVar}}")
46-
}{{end}}{{end}}{{end}}
47+
}{{else}}{{if eq .Type "bool" }}
48+
if _, exists = os.LookupEnv("{{$envVar}}"); {{$.StructVar}}.{{.Name}}|| exists {
49+
{{$.StructVar}}.{{.Name}} = true
50+
}{{end}}{{end}}{{end}}{{end}}
4751

4852
}
4953

0 commit comments

Comments
 (0)