mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 12:58:35 +07:00
docs: Enhance automatic document generation (#227)
* Enhance automatic document generation * update contribuor guide * fix broken link
This commit is contained in:
@@ -9,6 +9,9 @@ var jsonCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "json [PATH]",
|
||||
Short: "Generate JSON of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewJSON(settings))
|
||||
},
|
||||
|
||||
@@ -10,26 +10,35 @@ var markdownCmd = &cobra.Command{
|
||||
Use: "markdown [PATH]",
|
||||
Aliases: []string{"md"},
|
||||
Short: "Generate Markdown of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewTable(settings))
|
||||
},
|
||||
}
|
||||
|
||||
var mdTableCmd = &cobra.Command{
|
||||
var markdownTableCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "table [PATH]",
|
||||
Aliases: []string{"tbl"},
|
||||
Short: "Generate Markdown tables of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewTable(settings))
|
||||
},
|
||||
}
|
||||
|
||||
var mdDocumentCmd = &cobra.Command{
|
||||
var markdownDocumentCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "document [PATH]",
|
||||
Aliases: []string{"doc"},
|
||||
Short: "Generate Markdown document of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewDocument(settings))
|
||||
},
|
||||
@@ -41,8 +50,8 @@ func init() {
|
||||
markdownCmd.PersistentFlags().BoolVar(new(bool), "no-escape", false, "do not escape special characters")
|
||||
markdownCmd.PersistentFlags().IntVar(&settings.MarkdownIndent, "indent", 2, "indention level of Markdown sections [1, 2, 3, 4, 5]")
|
||||
|
||||
markdownCmd.AddCommand(mdTableCmd)
|
||||
markdownCmd.AddCommand(mdDocumentCmd)
|
||||
markdownCmd.AddCommand(markdownTableCmd)
|
||||
markdownCmd.AddCommand(markdownDocumentCmd)
|
||||
|
||||
rootCmd.AddCommand(markdownCmd)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ var prettyCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "pretty [PATH]",
|
||||
Short: "Generate colorized pretty of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewPretty(settings))
|
||||
},
|
||||
|
||||
18
cmd/root.go
18
cmd/root.go
@@ -12,7 +12,6 @@ import (
|
||||
var settings = print.NewSettings()
|
||||
var options = module.NewOptions()
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Args: cobra.NoArgs,
|
||||
Use: "terraform-docs",
|
||||
@@ -71,20 +70,9 @@ func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
// FormatterCmds returns list of available formatter
|
||||
// commands (e.g. markdown, json, yaml) and ignores
|
||||
// the other commands (e.g. completion, version, help)
|
||||
func FormatterCmds() []*cobra.Command {
|
||||
return []*cobra.Command{
|
||||
jsonCmd,
|
||||
prettyCmd,
|
||||
mdDocumentCmd,
|
||||
mdTableCmd,
|
||||
tfvarsHCLCmd,
|
||||
tfvarsJSONCmd,
|
||||
xmlCmd,
|
||||
yamlCmd,
|
||||
}
|
||||
// RootCmd represents the base command when called without any subcommands
|
||||
func RootCmd() *cobra.Command {
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
func doPrint(path string, printer print.Format) error {
|
||||
|
||||
@@ -9,12 +9,18 @@ var tfvarsCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "tfvars [PATH]",
|
||||
Short: "Generate terraform.tfvars of inputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
}
|
||||
|
||||
var tfvarsHCLCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "hcl [PATH]",
|
||||
Short: "Generate HCL format of terraform.tfvars of inputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewTfvarsHCL(settings))
|
||||
},
|
||||
@@ -24,6 +30,9 @@ var tfvarsJSONCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "json [PATH]",
|
||||
Short: "Generate JSON format of terraform.tfvars of inputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewTfvarsJSON(settings))
|
||||
},
|
||||
|
||||
@@ -9,6 +9,9 @@ var xmlCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "xml [PATH]",
|
||||
Short: "Generate XML of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewXML(settings))
|
||||
},
|
||||
|
||||
@@ -9,6 +9,9 @@ var yamlCmd = &cobra.Command{
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "yaml [PATH]",
|
||||
Short: "Generate YAML of inputs and outputs",
|
||||
Annotations: map[string]string{
|
||||
"kind": "formatter",
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return doPrint(args[0], format.NewYAML(settings))
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user