mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 12:58:35 +07:00
use /** comment for module commnet
terraform doesnt like multiline // comments i guess
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
//
|
||||
// Module usage:
|
||||
//
|
||||
// module "foo" {
|
||||
// source = "github.com/foo/baz"
|
||||
// subnet_ids = "${join(",", subnet.*.id)}"
|
||||
// }
|
||||
//
|
||||
/**
|
||||
* Module usage:
|
||||
*
|
||||
* module "foo" {
|
||||
* source = "github.com/foo/baz"
|
||||
* subnet_ids = "${join(",", subnet.*.id)}"
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
variable "subnet_ids" {
|
||||
description = "a comma-separated list of subnet IDs"
|
||||
|
||||
42
doc/doc.go
42
doc/doc.go
@@ -42,15 +42,7 @@ func Create(files map[string]*ast.File) *Doc {
|
||||
comments := f.Comments
|
||||
|
||||
if filename == "main.tf" && len(comments) > 0 {
|
||||
if c := comments[0]; c.Pos().Line == 1 {
|
||||
for _, item := range c.List {
|
||||
if !strings.HasPrefix(item.Text, "//") {
|
||||
break
|
||||
}
|
||||
|
||||
doc.Comment += strings.TrimPrefix(item.Text, "//") + "\n"
|
||||
}
|
||||
}
|
||||
doc.Comment = header(comments[0])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,3 +136,35 @@ func comment(l []*ast.Comment) string {
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
// Header returns the header comment from the list
|
||||
// or an empty comment. The head comment must start
|
||||
// at line 1 and start with `/**`.
|
||||
func header(c *ast.CommentGroup) (comment string) {
|
||||
if len(c.List) == 0 {
|
||||
return comment
|
||||
}
|
||||
|
||||
if c.Pos().Line != 1 {
|
||||
return comment
|
||||
}
|
||||
|
||||
cm := strings.TrimSpace(c.List[0].Text)
|
||||
|
||||
if strings.HasPrefix(cm, "/**") {
|
||||
lines := strings.Split(cm, "\n")
|
||||
|
||||
if len(lines) < 2 {
|
||||
return comment
|
||||
}
|
||||
|
||||
lines = lines[1 : len(lines)-1]
|
||||
for _, l := range lines {
|
||||
l = strings.TrimSpace(l)
|
||||
l = strings.TrimPrefix(l, "*")
|
||||
comment += l + "\n"
|
||||
}
|
||||
}
|
||||
|
||||
return comment
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user