From f46a48b46bfa4aac52d0695158ce60e59094f5de Mon Sep 17 00:00:00 2001 From: Khosrow Moossavi Date: Mon, 26 Jul 2021 20:09:37 -0400 Subject: [PATCH] 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 --- docs/user-guide/configuration.md | 5 ++++- internal/cli/run.go | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index 89a186c..085739c 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -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 diff --git a/internal/cli/run.go b/internal/cli/run.go index 46d7277..e2397a0 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -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