Attempt looking up config file in .config folder

The updated order of trying to look up for .terraform-docs.yml config
file, now, is:

1. root of module directory
2. `.config/` folder at root of module directory
3. current directory
4. `.config/` folder at current directory
5. `$HOME/.tfdocs.d/`

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
Khosrow Moossavi
2021-07-26 20:09:37 -04:00
parent 59a9f4e943
commit f46a48b46b
2 changed files with 9 additions and 4 deletions

View File

@@ -39,10 +39,13 @@ $ tree
$ terraform-docs -c .tfdocs-config.yml .
```
As of `v0.13.0`, the order for looking for config file is:
As of `v0.13.0`, the order for looking for config file is *(2 and 4 were added
in `v0.15.0`)*:
1. root of module directory
1. `.config/` folder at root of module directory
1. current directory
1. `.config/` folder at current directory
1. `$HOME/.tfdocs.d/`
if `.terraform-docs.yml` is found in any of the folders above, that will take

View File

@@ -61,9 +61,11 @@ func PreRunEFunc(config *Config) func(*cobra.Command, []string) error { //nolint
v.SetConfigType("yml")
}
v.AddConfigPath(args[0]) // first look at module root
v.AddConfigPath(".") // then current directory
v.AddConfigPath("$HOME/.tfdocs.d") // and finally $HOME/.tfdocs.d/
v.AddConfigPath(args[0]) // first look at module root
v.AddConfigPath(args[0] + "/.config") // then .config/ folder at module root
v.AddConfigPath(".") // then current directory
v.AddConfigPath(".config") // then .config/ folder at current directory
v.AddConfigPath("$HOME/.tfdocs.d") // and finally $HOME/.tfdocs.d/
if err := v.ReadInConfig(); err != nil {
var perr *os.PathError