-
Notifications
You must be signed in to change notification settings - Fork 24
/
readme.go
42 lines (31 loc) · 903 Bytes
/
readme.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
40
41
42
package pike
import (
"errors"
"os"
"strings"
"github.com/rs/zerolog/log"
)
// Readme Updates a README.md file.
func Readme(dirName string, output string, init bool, autoAppend bool) error {
file := dirName + "/README.md"
if _, err := os.Stat(file); errors.Is(err, os.ErrNotExist) {
return err
}
OutPolicy, err2 := MakePolicy(dirName, nil, init, false)
if err2 != nil {
log.Print("failed to make policy")
return err2
}
var markdown string
switch strings.ToLower(output) {
case terraform:
markdown = "\nThe Terraform resource required is:\n\n```golang\n" + OutPolicy.AsString(output) + "\n```\n"
case "json":
markdown = "\nThe Policy required is:\n\n```json\n" + OutPolicy.AsString(output) + "\n```\n"
default:
return errors.New("output formats are terraform or json")
}
err := ReplaceSection(file, markdown, autoAppend)
log.Print("readme updated")
return err
}