Fix some more Resolver changes.
This commit is contained in:
@@ -43,7 +43,7 @@ type Kong struct {
|
|||||||
Stderr io.Writer
|
Stderr io.Writer
|
||||||
|
|
||||||
bindings bindings
|
bindings bindings
|
||||||
loader ConfigurationFunc
|
loader ConfigurationLoader
|
||||||
resolvers []Resolver
|
resolvers []Resolver
|
||||||
registry *Registry
|
registry *Registry
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ func (k *Kong) FatalIfErrorf(err error, args ...interface{}) {
|
|||||||
// LoadConfig from path using the loader configured via Configuration(loader).
|
// LoadConfig from path using the loader configured via Configuration(loader).
|
||||||
//
|
//
|
||||||
// "path" will have ~/ expanded.
|
// "path" will have ~/ expanded.
|
||||||
func (k *Kong) LoadConfig(path string) (ResolverFunc, error) {
|
func (k *Kong) LoadConfig(path string) (Resolver, error) {
|
||||||
path = expandPath(path)
|
path = expandPath(path)
|
||||||
r, err := os.Open(path) // nolint: gas
|
r, err := os.Open(path) // nolint: gas
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+5
-5
@@ -188,17 +188,17 @@ func Resolvers(resolvers ...Resolver) OptionFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigurationFunc is a function that builds a resolver from a file.
|
// ConfigurationLoader is a function that builds a resolver from a file.
|
||||||
type ConfigurationFunc func(r io.Reader) (ResolverFunc, error)
|
type ConfigurationLoader func(r io.Reader) (Resolver, error)
|
||||||
|
|
||||||
// Configuration provides Kong with support for loading defaults from a set of configuration files.
|
// 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.
|
// ~ 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 {
|
return func(k *Kong) error {
|
||||||
k.loader = loader
|
k.loader = loader
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
|
|||||||
+2
-2
@@ -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.
|
// JSON returns a Resolver that retrieves values from a JSON source.
|
||||||
//
|
//
|
||||||
// Hyphens in flag names are replaced with underscores.
|
// 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{}{}
|
values := map[string]interface{}{}
|
||||||
err := json.NewDecoder(r).Decode(&values)
|
err := json.NewDecoder(r).Decode(&values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
name := strings.Replace(flag.Name, "-", "_", -1)
|
||||||
raw, ok := values[name]
|
raw, ok := values[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user