allow any config file name if specified directly (#189)
Currently, we require that config file names end with `.yml` or `.yaml`. This is because if the user points `-config` at a directory of files, we only want to use the YAML files in that directory. But this makes it more difficult to use the `-test -config` option because config management tools might not have an extension on the file when preparing a new config file. This change makes it so that if you point `-config file` directly at a file, it uses it no matter what the extension is.
This commit is contained in:
parent
4d1928f1e3
commit
fb9b36f677
14
config.go
14
config.go
|
@ -35,7 +35,7 @@ func (c *Config) Load(path string) error {
|
||||||
c.path = path
|
c.path = path
|
||||||
c.files = make([]string, 0)
|
c.files = make([]string, 0)
|
||||||
|
|
||||||
err := c.resolve(path)
|
err := c.resolve(path, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -234,14 +234,16 @@ func (c *Config) get(k string, v interface{}) interface{} {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) resolve(path string) error {
|
// direct signifies if this is the config path directly specified by the user,
|
||||||
|
// versus a file/dir found by recursing into that path
|
||||||
|
func (c *Config) resolve(path string, direct bool) error {
|
||||||
i, err := os.Stat(path)
|
i, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !i.IsDir() {
|
if !i.IsDir() {
|
||||||
c.addFile(path)
|
c.addFile(path, direct)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +253,7 @@ func (c *Config) resolve(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
err := c.resolve(filepath.Join(path, p))
|
err := c.resolve(filepath.Join(path, p), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -260,10 +262,10 @@ func (c *Config) resolve(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) addFile(path string) error {
|
func (c *Config) addFile(path string, direct bool) error {
|
||||||
ext := filepath.Ext(path)
|
ext := filepath.Ext(path)
|
||||||
|
|
||||||
if ext != ".yaml" && ext != ".yml" {
|
if !direct && ext != ".yaml" && ext != ".yml" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue