Merge pull request #1086 from akramarenkov/fix-altsrc-nil-source-flag
Fix bug 'Unable to load file' in altsrc
This commit is contained in:
commit
39f9fbd723
6
altsrc/default_input_source.go
Normal file
6
altsrc/default_input_source.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package altsrc
|
||||||
|
|
||||||
|
// defaultInputSource creates a default InputSourceContext.
|
||||||
|
func defaultInputSource() (InputSourceContext, error) {
|
||||||
|
return &MapInputSource{file: "", valueMap: map[interface{}]interface{}{}}, nil
|
||||||
|
}
|
@ -17,8 +17,12 @@ import (
|
|||||||
// by the given flag.
|
// by the given flag.
|
||||||
func NewJSONSourceFromFlagFunc(flag string) func(c *cli.Context) (InputSourceContext, error) {
|
func NewJSONSourceFromFlagFunc(flag string) func(c *cli.Context) (InputSourceContext, error) {
|
||||||
return func(context *cli.Context) (InputSourceContext, error) {
|
return func(context *cli.Context) (InputSourceContext, error) {
|
||||||
|
if context.IsSet(flag) {
|
||||||
return NewJSONSourceFromFile(context.String(flag))
|
return NewJSONSourceFromFile(context.String(flag))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return defaultInputSource()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewJSONSourceFromFile returns an InputSourceContext suitable for
|
// NewJSONSourceFromFile returns an InputSourceContext suitable for
|
||||||
|
@ -87,9 +87,13 @@ func NewTomlSourceFromFile(file string) (InputSourceContext, error) {
|
|||||||
// NewTomlSourceFromFlagFunc creates a new TOML InputSourceContext from a provided flag name and source context.
|
// NewTomlSourceFromFlagFunc creates a new TOML InputSourceContext from a provided flag name and source context.
|
||||||
func NewTomlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) {
|
func NewTomlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) {
|
||||||
return func(context *cli.Context) (InputSourceContext, error) {
|
return func(context *cli.Context) (InputSourceContext, error) {
|
||||||
|
if context.IsSet(flagFileName) {
|
||||||
filePath := context.String(flagFileName)
|
filePath := context.String(flagFileName)
|
||||||
return NewTomlSourceFromFile(filePath)
|
return NewTomlSourceFromFile(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return defaultInputSource()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readCommandToml(filePath string, container interface{}) (err error) {
|
func readCommandToml(filePath string, container interface{}) (err error) {
|
||||||
|
@ -33,9 +33,13 @@ func NewYamlSourceFromFile(file string) (InputSourceContext, error) {
|
|||||||
// NewYamlSourceFromFlagFunc creates a new Yaml InputSourceContext from a provided flag name and source context.
|
// NewYamlSourceFromFlagFunc creates a new Yaml InputSourceContext from a provided flag name and source context.
|
||||||
func NewYamlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) {
|
func NewYamlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) {
|
||||||
return func(context *cli.Context) (InputSourceContext, error) {
|
return func(context *cli.Context) (InputSourceContext, error) {
|
||||||
|
if context.IsSet(flagFileName) {
|
||||||
filePath := context.String(flagFileName)
|
filePath := context.String(flagFileName)
|
||||||
return NewYamlSourceFromFile(filePath)
|
return NewYamlSourceFromFile(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return defaultInputSource()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readCommandYaml(filePath string, container interface{}) (err error) {
|
func readCommandYaml(filePath string, container interface{}) (err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user