mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 04:48:33 +07:00
Generate submodules documents with '--resurcive' flag
Considering the file strucutre below of main module and its submodules, now it is possible to generate documentation for them main and all its submodules in one execution, with `--recursive` flag. Note that generating documentation recursively is allowed only with `--output-file` set. Path to find submodules can be configured with `--recursive-path` (defaults to `modules`). Each submodule can also have their own `.terraform-docs.yml` confi file, to override configuration from root module. ``` . ├── README.md ├── main.tf ├── modules │ └── my-sub-module │ ├── README.md │ ├── main.tf │ ├── variables.tf │ └── versions.tf ├── outputs.tf ├── variables.tf └── versions.tf ``` Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
@@ -19,15 +19,15 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'asciidoc' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "asciidoc [PATH]",
|
||||
Aliases: []string{"adoc"},
|
||||
Short: "Generate AsciiDoc of inputs and outputs",
|
||||
Annotations: cli.Annotations("asciidoc"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
|
||||
// flags
|
||||
@@ -39,8 +39,8 @@ func NewCommand(config *cli.Config) *cobra.Command {
|
||||
cmd.PersistentFlags().BoolVar(&config.Settings.Type, "type", true, "show Type column or section")
|
||||
|
||||
// subcommands
|
||||
cmd.AddCommand(document.NewCommand(config))
|
||||
cmd.AddCommand(table.NewCommand(config))
|
||||
cmd.AddCommand(document.NewCommand(runtime, config))
|
||||
cmd.AddCommand(table.NewCommand(runtime, config))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'asciidoc document' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "document [PATH]",
|
||||
Aliases: []string{"doc"},
|
||||
Short: "Generate AsciiDoc document of inputs and outputs",
|
||||
Annotations: cli.Annotations("asciidoc document"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'asciidoc table' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "table [PATH]",
|
||||
Aliases: []string{"tbl"},
|
||||
Short: "Generate AsciiDoc tables of inputs and outputs",
|
||||
Annotations: cli.Annotations("asciidoc table"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'json' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "json [PATH]",
|
||||
Short: "Generate JSON of inputs and outputs",
|
||||
Annotations: cli.Annotations("json"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
|
||||
// flags
|
||||
|
||||
@@ -17,15 +17,15 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'markdown document' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "document [PATH]",
|
||||
Aliases: []string{"doc"},
|
||||
Short: "Generate Markdown document of inputs and outputs",
|
||||
Annotations: cli.Annotations("markdown document"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'markdown' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "markdown [PATH]",
|
||||
Aliases: []string{"md"},
|
||||
Short: "Generate Markdown of inputs and outputs",
|
||||
Annotations: cli.Annotations("markdown"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
|
||||
// flags
|
||||
@@ -41,8 +41,8 @@ func NewCommand(config *cli.Config) *cobra.Command {
|
||||
cmd.PersistentFlags().BoolVar(&config.Settings.Type, "type", true, "show Type column or section")
|
||||
|
||||
// subcommands
|
||||
cmd.AddCommand(document.NewCommand(config))
|
||||
cmd.AddCommand(table.NewCommand(config))
|
||||
cmd.AddCommand(document.NewCommand(runtime, config))
|
||||
cmd.AddCommand(table.NewCommand(runtime, config))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'markdown table' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "table [PATH]",
|
||||
Aliases: []string{"tbl"},
|
||||
Short: "Generate Markdown tables of inputs and outputs",
|
||||
Annotations: cli.Annotations("markdown table"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for pretty formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "pretty [PATH]",
|
||||
Short: "Generate colorized pretty of inputs and outputs",
|
||||
Annotations: cli.Annotations("pretty"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
|
||||
// flags
|
||||
|
||||
23
cmd/root.go
23
cmd/root.go
@@ -43,6 +43,7 @@ func Execute() error {
|
||||
// NewCommand returns a new cobra.Command for 'root' command
|
||||
func NewCommand() *cobra.Command {
|
||||
config := cli.DefaultConfig()
|
||||
runtime := cli.NewRuntime(config)
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Use: "terraform-docs [PATH]",
|
||||
@@ -52,12 +53,14 @@ func NewCommand() *cobra.Command {
|
||||
SilenceUsage: true,
|
||||
SilenceErrors: true,
|
||||
Annotations: cli.Annotations("root"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
|
||||
// flags
|
||||
cmd.PersistentFlags().StringVarP(&config.File, "config", "c", ".terraform-docs.yml", "config file name")
|
||||
cmd.PersistentFlags().BoolVar(&config.Recursive, "recursive", false, "update submodules recursively (default false)")
|
||||
cmd.PersistentFlags().StringVar(&config.RecursivePath, "recursive-path", "modules", "submodules path to recursively update")
|
||||
|
||||
cmd.PersistentFlags().StringSliceVar(&config.Sections.Show, "show", []string{}, "show section ["+cli.AllSections+"]")
|
||||
cmd.PersistentFlags().StringSliceVar(&config.Sections.Hide, "hide", []string{}, "hide section ["+cli.AllSections+"]")
|
||||
@@ -79,14 +82,14 @@ func NewCommand() *cobra.Command {
|
||||
cmd.PersistentFlags().StringVar(&config.OutputValues.From, "output-values-from", "", "inject output values from file into outputs (default \"\")")
|
||||
|
||||
// formatter subcommands
|
||||
cmd.AddCommand(asciidoc.NewCommand(config))
|
||||
cmd.AddCommand(json.NewCommand(config))
|
||||
cmd.AddCommand(markdown.NewCommand(config))
|
||||
cmd.AddCommand(pretty.NewCommand(config))
|
||||
cmd.AddCommand(tfvars.NewCommand(config))
|
||||
cmd.AddCommand(toml.NewCommand(config))
|
||||
cmd.AddCommand(xml.NewCommand(config))
|
||||
cmd.AddCommand(yaml.NewCommand(config))
|
||||
cmd.AddCommand(asciidoc.NewCommand(runtime, config))
|
||||
cmd.AddCommand(json.NewCommand(runtime, config))
|
||||
cmd.AddCommand(markdown.NewCommand(runtime, config))
|
||||
cmd.AddCommand(pretty.NewCommand(runtime, config))
|
||||
cmd.AddCommand(tfvars.NewCommand(runtime, config))
|
||||
cmd.AddCommand(toml.NewCommand(runtime, config))
|
||||
cmd.AddCommand(xml.NewCommand(runtime, config))
|
||||
cmd.AddCommand(yaml.NewCommand(runtime, config))
|
||||
|
||||
// other subcommands
|
||||
cmd.AddCommand(completion.NewCommand())
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'tfvars hcl' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "hcl [PATH]",
|
||||
Short: "Generate HCL format of terraform.tfvars of inputs",
|
||||
Annotations: cli.Annotations("tfvars hcl"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
cmd.PersistentFlags().BoolVar(&config.Settings.Description, "description", false, "show Descriptions on variables")
|
||||
return cmd
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'tfvars json' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "json [PATH]",
|
||||
Short: "Generate JSON format of terraform.tfvars of inputs",
|
||||
Annotations: cli.Annotations("tfvars json"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'tfvars' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "tfvars [PATH]",
|
||||
@@ -28,8 +28,8 @@ func NewCommand(config *cli.Config) *cobra.Command {
|
||||
}
|
||||
|
||||
// subcommands
|
||||
cmd.AddCommand(hcl.NewCommand(config))
|
||||
cmd.AddCommand(json.NewCommand(config))
|
||||
cmd.AddCommand(hcl.NewCommand(runtime, config))
|
||||
cmd.AddCommand(json.NewCommand(runtime, config))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'toml' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "toml [PATH]",
|
||||
Short: "Generate TOML of inputs and outputs",
|
||||
Annotations: cli.Annotations("toml"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'xml' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "xml [PATH]",
|
||||
Short: "Generate XML of inputs and outputs",
|
||||
Annotations: cli.Annotations("xml"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ import (
|
||||
)
|
||||
|
||||
// NewCommand returns a new cobra.Command for 'yaml' formatter
|
||||
func NewCommand(config *cli.Config) *cobra.Command {
|
||||
func NewCommand(runtime *cli.Runtime, config *cli.Config) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "yaml [PATH]",
|
||||
Short: "Generate YAML of inputs and outputs",
|
||||
Annotations: cli.Annotations("yaml"),
|
||||
PreRunE: cli.PreRunEFunc(config),
|
||||
RunE: cli.RunEFunc(config),
|
||||
PreRunE: runtime.PreRunEFunc,
|
||||
RunE: runtime.RunEFunc,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user