use /** comment for module commnet

terraform doesnt like multiline // comments i guess
This commit is contained in:
Amir Abushareb
2016-06-15 14:50:45 +02:00
parent ba2b4831ca
commit 5cae48f458
2 changed files with 42 additions and 17 deletions

View File

@@ -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"

View File

@@ -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
}