Treat envars as higher priority than resolvers.

This commit is contained in:
Alec Thomas
2018-09-21 12:06:24 +10:00
parent 026359efd8
commit 3a832f8343
5 changed files with 28 additions and 52 deletions
-14
View File
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"strings"
)
@@ -61,16 +60,3 @@ func jsonDecodeValue(sep rune, value interface{}) (string, error) {
}
return "", fmt.Errorf("unsupported JSON value %v (of type %T)", value, value)
}
// Envars resolves flag values using the `env:"<name>"` tag. It ignores flags without this tag.
//
// This resolver is installed by default.
func Envars() ResolverFunc {
return func(context *Context, parent *Path, flag *Flag) (string, error) {
if flag.Tag.Env == "" {
return "", nil
}
v, _ := os.LookupEnv(flag.Tag.Env)
return v, nil
}
}