Skip to content

Commit

Permalink
Change featureMatrix to use the new replace function
Browse files Browse the repository at this point in the history
(it has more error checks)
  • Loading branch information
systemcrash committed Mar 18, 2023
1 parent 4f46b31 commit c03f60e
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions build/generate/featureMatrix.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"os"
"sort"
"strings"

Expand All @@ -18,9 +17,9 @@ func generateFeatureMatrix() error {
return err
}

replaceInlineContent(
replaceTextBetweenMarkers(
"documentation/providers.md",
"<!-- provider-matrix-start -->",
"<!-- provider-matrix-start -->\n",
"<!-- provider-matrix-end -->",
markdownTable,
)
Expand Down Expand Up @@ -290,29 +289,3 @@ type FeatureMatrix struct {
Features []string
Providers map[string]FeatureMap
}

func replaceInlineContent(
file string,
startMarker string,
endMarker string,
newContent string,
) {
contentBytes, err := os.ReadFile(file)
if err != nil {
panic(err)
}
content := string(contentBytes)

start := strings.Index(content, startMarker)
end := strings.Index(content, endMarker)

newContentString := startMarker + "\n" + newContent + endMarker
newContentBytes := []byte(newContentString)
contentBytes = []byte(content)
contentBytes = append(contentBytes[:start], append(newContentBytes, contentBytes[end+len(endMarker):]...)...)

err = os.WriteFile(file, contentBytes, 0644)
if err != nil {
panic(err)
}
}

0 comments on commit c03f60e

Please sign in to comment.