Consider empty environment variables as set

When assigning values to flags (also when interogatting via
`context.(Global)IsSet`.

For boolean flags, consider empty as `false`.

Using `syscall.Getenv` rather than `os.LookupEnv` in order to support
older Golang versions.
This commit is contained in:
Jesse Szwedko
2016-09-11 20:32:43 -07:00
parent 7a5dacbc41
commit a00c3f5872
5 changed files with 100 additions and 22 deletions

View File

@@ -2,9 +2,9 @@ package altsrc
import (
"fmt"
"os"
"strconv"
"strings"
"syscall"
"gopkg.in/urfave/cli.v1"
)
@@ -237,13 +237,11 @@ func (f *Float64Flag) ApplyInputSourceValue(context *cli.Context, isc InputSourc
func isEnvVarSet(envVars string) bool {
for _, envVar := range strings.Split(envVars, ",") {
envVar = strings.TrimSpace(envVar)
if envVal := os.Getenv(envVar); envVal != "" {
if _, ok := syscall.Getenv(envVar); ok {
// TODO: Can't use this for bools as
// set means that it was true or false based on
// Bool flag type, should work for other types
if len(envVal) > 0 {
return true
}
return true
}
}