-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto add flags docs into the README (#147)
- Loading branch information
1 parent
5213a4f
commit 6218976
Showing
5 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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!") | ||
} |