Add configuration loading + docs + linter fixes.

This commit is contained in:
Alec Thomas
2018-06-13 10:33:22 +10:00
parent a5c97373ba
commit 232faad0a0
15 changed files with 218 additions and 17 deletions
+4 -4
View File
@@ -11,10 +11,10 @@ import (
// ResolverFunc resolves a Flag value from an external source.
type ResolverFunc func(context *Context, parent *Path, flag *Flag) (string, error)
// JSONResolver returns a Resolver that retrieves values from a JSON source.
// JSON returns a Resolver that retrieves values from a JSON source.
//
// Hyphens in flag names are replaced with underscores.
func JSONResolver(r io.Reader) (ResolverFunc, error) {
func JSON(r io.Reader) (ResolverFunc, error) {
values := map[string]interface{}{}
err := json.NewDecoder(r).Decode(&values)
if err != nil {
@@ -61,10 +61,10 @@ func jsonDecodeValue(sep rune, value interface{}) (string, error) {
return "", fmt.Errorf("unsupported JSON value %v (of type %T)", value, value)
}
// EnvResolver resolves flag values using the `env:"<name>"` tag. It ignores flags without this tag.
// Envars resolves flag values using the `env:"<name>"` tag. It ignores flags without this tag.
//
// This resolver is installed by default.
func EnvResolver() ResolverFunc {
func Envars() ResolverFunc {
return func(context *Context, parent *Path, flag *Flag) (string, error) {
if flag.Tag.Env == "" {
return "", nil