Expand variables in config paths.

This commit is contained in:
Alec Thomas
2020-03-05 11:27:53 +11:00
parent b8c82fea7c
commit 109dce7ea5
2 changed files with 7 additions and 2 deletions
+6 -1
View File
@@ -338,9 +338,14 @@ 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 ~ and any variables expanded.
func (k *Kong) LoadConfig(path string) (Resolver, error) { func (k *Kong) LoadConfig(path string) (Resolver, error) {
var err error
path = ExpandPath(path) path = ExpandPath(path)
path, err = interpolate(path, k.vars)
if err != nil {
return nil, err
}
r, err := os.Open(path) // nolint: gas r, err := os.Open(path) // nolint: gas
if err != nil { if err != nil {
return nil, err return nil, err
+1 -1
View File
@@ -235,7 +235,7 @@ type ConfigurationLoader func(r io.Reader) (Resolver, error)
// //
// Note: The JSON function is a ConfigurationLoader. // 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 { func Configuration(loader ConfigurationLoader, paths ...string) Option {
return OptionFunc(func(k *Kong) error { return OptionFunc(func(k *Kong) error {
k.loader = loader k.loader = loader