in cobra/aid/render.go [143:208]
func writeOutputs() error {
outputs, err := os.Open("outputs.tf")
if err != nil {
logrus.Fatal(err)
}
defer outputs.Close()
// create INPUTS.md
outs, err := os.OpenFile("OUTPUTS.md", os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
logrus.Println(err)
}
defer outs.Close()
if _, err := outs.WriteString("| Name | Description |\n|------|-------------|\n"); err != nil {
logrus.Println(err)
}
var outName, outDescription string
scanner := bufio.NewScanner(outputs)
for scanner.Scan() {
line := scanner.Text()
// skip empty lines
if len(line) > 0 {
if strings.Contains(line, "output") && strings.Contains(line, "{") {
out, found := helper.GetStringBetweenDoubleQuotes(line)
if found {
outName = out
}
}
if strings.Contains(line, "description") && strings.Contains(line, "=") {
slc := helper.GetStringTrimmed(line, "=")
if slc[0] == "description" {
out, found := helper.GetStringBetweenDoubleQuotes(slc[1])
if found {
outDescription = out
}
}
}
// end of the output declaration
if strings.Contains(line, "}") && len(line) == 1 {
if len(outName) > 0 && len(outDescription) > 0 {
result := fmt.Sprintf("| %s | %s | |\n", outName, outDescription)
if _, err := outs.WriteString(result); err != nil {
logrus.Println(err)
}
outName, outDescription = "", ""
}
}
}
}
if err := scanner.Err(); err != nil {
logrus.Fatal(err)
}
return err
}