Make main module doc optional when in recursive generation

Signed-off-by: Blake Gong <blakegong@gmail.com>
This commit is contained in:
Blake Gong
2022-07-12 01:07:32 +08:00
committed by Khosrow Moossavi
parent e9192750e0
commit 59eb90fc86
7 changed files with 26 additions and 7 deletions

View File

@@ -180,6 +180,7 @@ footer-from: ""
recursive:
enabled: false
path: modules
include-main: true
sections:
hide: []

View File

@@ -62,6 +62,7 @@ func NewCommand() *cobra.Command {
cmd.PersistentFlags().StringVarP(&config.File, "config", "c", ".terraform-docs.yml", "config file name")
cmd.PersistentFlags().BoolVar(&config.Recursive.Enabled, "recursive", false, "update submodules recursively (default false)")
cmd.PersistentFlags().StringVar(&config.Recursive.Path, "recursive-path", "modules", "submodules path to recursively update")
cmd.PersistentFlags().BoolVar(&config.Recursive.IncludeMain, "recursive-include-main", true, "include the main module (default true)")
cmd.PersistentFlags().StringSliceVar(&config.Sections.Show, "show", []string{}, "show section ["+print.AllSections+"]")
cmd.PersistentFlags().StringSliceVar(&config.Sections.Hide, "hide", []string{}, "hide section ["+print.AllSections+"]")

View File

@@ -22,6 +22,8 @@ set.
Path to find submodules can be configured with `--recursive-path` (defaults to
`modules`).
The main module document is generated by default, which can be configured with `--recursive-include-main`. Should the main module document be excluded from document generation, use `--recursive-include-main=false`.
Each submodule can also have their own `.terraform-docs.yml` config file, to
override configuration from root module.

View File

@@ -79,6 +79,7 @@ footer-from: ""
recursive:
enabled: false
path: modules
include-main: true
sections:
hide: []

View File

@@ -32,6 +32,7 @@ Available options with their default values.
recursive:
enabled: false
path: modules
include-main: true
```
## Examples
@@ -50,3 +51,12 @@ recursive:
enabled: true
path: submodules-folder
```
Skip the main module document, and only generate documents for submodules.
```yaml
recursive:
enabled: true
path: submodules-folder
include-main: false
```

View File

@@ -94,9 +94,11 @@ type module struct {
// RunEFunc is the 'cobra.Command#RunE' function for 'formatter' commands. It attempts
// to discover submodules, on `--recursive` flag, and generates the content for them
// as well as the root module.
func (r *Runtime) RunEFunc(cmd *cobra.Command, args []string) error {
modules := []module{
{rootDir: r.rootDir, config: r.config},
func (r *Runtime) RunEFunc(cmd *cobra.Command, args []string) error { //nolint:gocyclo
modules := []module{}
if r.config.Recursive.IncludeMain {
modules = append(modules, module{r.rootDir, r.config})
}
// Generating content recursively is only allowed when `config.Output.File`

View File

@@ -73,14 +73,16 @@ func DefaultConfig() *Config {
}
type recursive struct {
Enabled bool `mapstructure:"enabled"`
Path string `mapstructure:"path"`
Enabled bool `mapstructure:"enabled"`
Path string `mapstructure:"path"`
IncludeMain bool `mapstructure:"include-main"`
}
func defaultRecursive() recursive {
return recursive{
Enabled: false,
Path: "modules",
Enabled: false,
Path: "modules",
IncludeMain: true,
}
}