From ea2049f3ede1b6f18015286750ff72924ae3180c Mon Sep 17 00:00:00 2001 From: Aleksei Zhogov Date: Fri, 13 Jul 2018 13:13:19 -0400 Subject: [PATCH] Fixed parsing of environment variables --- command/base_flags.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/command/base_flags.go b/command/base_flags.go index 8f4116c5531b..cc5bfbd31893 100644 --- a/command/base_flags.go +++ b/command/base_flags.go @@ -105,7 +105,7 @@ type IntVar struct { func (f *FlagSet) IntVar(i *IntVar) { initial := i.Default if v := os.Getenv(i.EnvVar); v != "" { - if i, err := strconv.ParseInt(v, 0, 64); err != nil { + if i, err := strconv.ParseInt(v, 0, 64); err == nil { initial = int(i) } } @@ -169,7 +169,7 @@ type Int64Var struct { func (f *FlagSet) Int64Var(i *Int64Var) { initial := i.Default if v := os.Getenv(i.EnvVar); v != "" { - if i, err := strconv.ParseInt(v, 0, 64); err != nil { + if i, err := strconv.ParseInt(v, 0, 64); err == nil { initial = i } } @@ -233,7 +233,7 @@ type UintVar struct { func (f *FlagSet) UintVar(i *UintVar) { initial := i.Default if v := os.Getenv(i.EnvVar); v != "" { - if i, err := strconv.ParseUint(v, 0, 64); err != nil { + if i, err := strconv.ParseUint(v, 0, 64); err == nil { initial = uint(i) } } @@ -297,7 +297,7 @@ type Uint64Var struct { func (f *FlagSet) Uint64Var(i *Uint64Var) { initial := i.Default if v := os.Getenv(i.EnvVar); v != "" { - if i, err := strconv.ParseUint(v, 0, 64); err != nil { + if i, err := strconv.ParseUint(v, 0, 64); err == nil { initial = i } } @@ -418,7 +418,7 @@ type Float64Var struct { func (f *FlagSet) Float64Var(i *Float64Var) { initial := i.Default if v := os.Getenv(i.EnvVar); v != "" { - if i, err := strconv.ParseFloat(v, 64); err != nil { + if i, err := strconv.ParseFloat(v, 64); err == nil { initial = i } } @@ -482,7 +482,7 @@ type DurationVar struct { func (f *FlagSet) DurationVar(i *DurationVar) { initial := i.Default if v := os.Getenv(i.EnvVar); v != "" { - if d, err := time.ParseDuration(appendDurationSuffix(v)); err != nil { + if d, err := time.ParseDuration(appendDurationSuffix(v)); err == nil { initial = d } }