From c935ea07dd037f8f3631a5db7ee8c085c16c5f69 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Fri, 21 Sep 2018 17:10:53 +1000 Subject: [PATCH] Fix some more Resolver changes. --- kong.go | 4 ++-- options.go | 10 +++++----- resolver.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kong.go b/kong.go index 5e31009..920e966 100644 --- a/kong.go +++ b/kong.go @@ -43,7 +43,7 @@ type Kong struct { Stderr io.Writer bindings bindings - loader ConfigurationFunc + loader ConfigurationLoader resolvers []Resolver registry *Registry @@ -332,7 +332,7 @@ func (k *Kong) FatalIfErrorf(err error, args ...interface{}) { // LoadConfig from path using the loader configured via Configuration(loader). // // "path" will have ~/ expanded. -func (k *Kong) LoadConfig(path string) (ResolverFunc, error) { +func (k *Kong) LoadConfig(path string) (Resolver, error) { path = expandPath(path) r, err := os.Open(path) // nolint: gas if err != nil { diff --git a/options.go b/options.go index 140c1e0..bcadf16 100644 --- a/options.go +++ b/options.go @@ -188,17 +188,17 @@ func Resolvers(resolvers ...Resolver) OptionFunc { } } -// ConfigurationFunc is a function that builds a resolver from a file. -type ConfigurationFunc func(r io.Reader) (ResolverFunc, error) +// ConfigurationLoader is a function that builds a resolver from a file. +type ConfigurationLoader func(r io.Reader) (Resolver, error) // Configuration provides Kong with support for loading defaults from a set of configuration files. // -// Paths will be opened in order, and "loader" will be used to provide a ResolverFunc which is registered with Kong. +// Paths will be opened in order, and "loader" will be used to provide a Resolver which is registered with Kong. // -// Note: The JSON function is a ConfigurationFunc. +// Note: The JSON function is a ConfigurationLoader. // // ~ expansion will occur on the provided paths. -func Configuration(loader ConfigurationFunc, paths ...string) OptionFunc { +func Configuration(loader ConfigurationLoader, paths ...string) OptionFunc { return func(k *Kong) error { k.loader = loader for _, path := range paths { diff --git a/resolver.go b/resolver.go index 5cc92ce..85063d9 100644 --- a/resolver.go +++ b/resolver.go @@ -31,13 +31,13 @@ func (r ResolverFunc) Validate(app *Application) error { return nil } // nolint // JSON returns a Resolver that retrieves values from a JSON source. // // Hyphens in flag names are replaced with underscores. -func JSON(r io.Reader) (ResolverFunc, error) { +func JSON(r io.Reader) (Resolver, error) { values := map[string]interface{}{} err := json.NewDecoder(r).Decode(&values) if err != nil { return nil, err } - f := func(context *Context, parent *Path, flag *Flag) (string, error) { + var f ResolverFunc = func(context *Context, parent *Path, flag *Flag) (string, error) { name := strings.Replace(flag.Name, "-", "_", -1) raw, ok := values[name] if !ok {