Fix some more Resolver changes.

This commit is contained in:
Alec Thomas
2018-09-21 17:10:53 +10:00
parent c112a076e7
commit c935ea07dd
3 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -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 {
+5 -5
View File
@@ -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 {
+2 -2
View File
@@ -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 {