Skip to content

Commit 3dc2349

Browse files
committed
- [!] fix bug: cli param should override Env var, not the other way
1 parent f7ad3a8 commit 3dc2349

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

test/commandlineFlag.ref

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,47 +73,47 @@ func initVals() {
7373
if _, exists = os.LookupEnv("EASYGEN_HTML"); Opts.HTML|| exists {
7474
Opts.HTML = true
7575
}
76-
if len(Opts.TemplateStr) == 0 ||
76+
if len(Opts.TemplateStr) == 0 &&
7777
len(os.Getenv("EASYGEN_TS")) != 0 {
7878
Opts.TemplateStr = os.Getenv("EASYGEN_TS")
7979
}
80-
if len(Opts.TemplateFile) == 0 ||
80+
if len(Opts.TemplateFile) == 0 &&
8181
len(os.Getenv("EASYGEN_F")) != 0 {
8282
Opts.TemplateFile = os.Getenv("EASYGEN_F")
8383
}
84-
if len(Opts.TemplateFile) == 0 ||
84+
if len(Opts.TemplateFile) == 0 &&
8585
len(os.Getenv("EASYGEN_TF")) != 0 {
8686
Opts.TemplateFile = os.Getenv("EASYGEN_TF")
8787
}
88-
if len(Opts.ExtYaml) == 0 ||
88+
if len(Opts.ExtYaml) == 0 &&
8989
len(os.Getenv("EASYGEN_EY")) != 0 {
9090
Opts.ExtYaml = os.Getenv("EASYGEN_EY")
9191
}
92-
if len(Opts.ExtTmpl) == 0 ||
92+
if len(Opts.ExtTmpl) == 0 &&
9393
len(os.Getenv("EASYGEN_ET")) != 0 {
9494
Opts.ExtTmpl = os.Getenv("EASYGEN_ET")
9595
}
96-
if len(Opts.StrFrom) == 0 ||
96+
if len(Opts.StrFrom) == 0 &&
9797
len(os.Getenv("EASYGEN_RF")) != 0 {
9898
Opts.StrFrom = os.Getenv("EASYGEN_RF")
9999
}
100-
if len(Opts.StrTo) == 0 ||
100+
if len(Opts.StrTo) == 0 &&
101101
len(os.Getenv("EASYGEN_RT")) != 0 {
102102
Opts.StrTo = os.Getenv("EASYGEN_RT")
103103
}
104-
if Opts.IntV == 0 ||
104+
if Opts.IntV == 0 &&
105105
len(os.Getenv("EASYGEN_INTV")) != 0 {
106106
if i, err := strconv.Atoi(os.Getenv("EASYGEN_INTV")); err == nil {
107107
Opts.IntV = i
108108
}
109109
}
110-
if Opts.Debug == 0 ||
110+
if Opts.Debug == 0 &&
111111
len(os.Getenv("EASYGEN_D")) != 0 {
112112
if i, err := strconv.Atoi(os.Getenv("EASYGEN_D")); err == nil {
113113
Opts.Debug = i
114114
}
115115
}
116-
if Opts.Debug == 0 ||
116+
if Opts.Debug == 0 &&
117117
len(os.Getenv("EASYGEN_DEBUG")) != 0 {
118118
if i, err := strconv.Atoi(os.Getenv("EASYGEN_DEBUG")); err == nil {
119119
Opts.Debug = i

test/commandlineFlag.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ func initVals() {
4545
// Now override those default values from environment variables{{range .Options}}{{if eq .Name "SEPARATOR" }}
4646

4747
{{else}}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .Flag)}}{{if eq .Type "string" }}{{if (stringsContains .Flag ",")}}{{$cf := .}}{{range (stringsSplit .Flag ",")}}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .)}}
48-
if len({{$.StructVar}}.{{$cf.Name}}) == 0 ||
48+
if len({{$.StructVar}}.{{$cf.Name}}) == 0 &&
4949
len(os.Getenv("{{$envVar}}")) != 0 {
5050
{{$.StructVar}}.{{$cf.Name}} = os.Getenv("{{$envVar}}")
5151
}{{end}}{{else}}
52-
if len({{$.StructVar}}.{{.Name}}) == 0 ||
52+
if len({{$.StructVar}}.{{.Name}}) == 0 &&
5353
len(os.Getenv("{{$envVar}}")) != 0 {
5454
{{$.StructVar}}.{{.Name}} = os.Getenv("{{$envVar}}")
5555
}{{end}}{{else}}{{if eq .Type "bool" }}
5656
if _, exists = os.LookupEnv("{{$envVar}}"); {{$.StructVar}}.{{.Name}}|| exists {
5757
{{$.StructVar}}.{{.Name}} = true
5858
}{{else}}{{if eq .Type "int" }}{{if (stringsContains .Flag ",")}}{{$cf := .}}{{range (stringsSplit .Flag ",")}}{{$envVar := printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .)}}
59-
if {{$.StructVar}}.{{$cf.Name}} == 0 ||
59+
if {{$.StructVar}}.{{$cf.Name}} == 0 &&
6060
len(os.Getenv("{{$envVar}}")) != 0 {
6161
if i, err := strconv.Atoi(os.Getenv("{{$envVar}}")); err == nil {
6262
{{$.StructVar}}.{{$cf.Name}} = i
6363
}
6464
}{{end}}{{else}}
65-
if {{$.StructVar}}.{{.Name}} == 0 ||
65+
if {{$.StructVar}}.{{.Name}} == 0 &&
6666
len(os.Getenv("{{$envVar}}")) != 0 {
6767
if i, err := strconv.Atoi(os.Getenv("{{$envVar}}")); err == nil {
6868
{{$.StructVar}}.{{.Name}} = i

0 commit comments

Comments
 (0)