-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmain.go
39 lines (32 loc) · 948 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"os"
"strings"
"github.com/coder/envbuilder"
)
const (
startSection = "<!--- START docsgen --->"
endSection = "<!--- END docsgen --->"
)
func main() {
readmePath := "README.md"
readmeFile, err := os.ReadFile(readmePath)
if err != nil {
panic("error reading " + readmePath + " file")
}
readmeContent := string(readmeFile)
startIndex := strings.Index(readmeContent, startSection)
endIndex := strings.Index(readmeContent, endSection)
if startIndex == -1 || endIndex == -1 {
panic("start or end section comments not found in the file.")
}
var options envbuilder.Options
mkd := "\n## Environment Variables\n\n" + options.Markdown()
modifiedContent := readmeContent[:startIndex+len(startSection)] + mkd + readmeContent[endIndex:]
err = os.WriteFile(readmePath, []byte(modifiedContent), 0644)
if err != nil {
panic(err)
}
fmt.Println("README updated successfully with the latest flags!")
}