Skip to content

Commit

Permalink
Fixed parsing of environment variables (#4925)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhogov authored and briankassouf committed Jul 13, 2018
1 parent c50881b commit 9c258c7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions command/base_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 9c258c7

Please sign in to comment.