From 109dce7ea5d32e63a96a2c234e991ea3ea470e77 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 5 Mar 2020 11:27:53 +1100 Subject: [PATCH] Expand variables in config paths. --- kong.go | 7 ++++++- options.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/kong.go b/kong.go index 882e4ad..3a61567 100644 --- a/kong.go +++ b/kong.go @@ -338,9 +338,14 @@ func (k *Kong) FatalIfErrorf(err error, args ...interface{}) { // LoadConfig from path using the loader configured via Configuration(loader). // -// "path" will have ~/ expanded. +// "path" will have ~ and any variables expanded. func (k *Kong) LoadConfig(path string) (Resolver, error) { + var err error path = ExpandPath(path) + path, err = interpolate(path, k.vars) + if err != nil { + return nil, err + } r, err := os.Open(path) // nolint: gas if err != nil { return nil, err diff --git a/options.go b/options.go index 66fd633..1464d71 100644 --- a/options.go +++ b/options.go @@ -235,7 +235,7 @@ type ConfigurationLoader func(r io.Reader) (Resolver, error) // // Note: The JSON function is a ConfigurationLoader. // -// ~ expansion will occur on the provided paths. +// ~ and variable expansion will occur on the provided paths. func Configuration(loader ConfigurationLoader, paths ...string) Option { return OptionFunc(func(k *Kong) error { k.loader = loader