go-KodeStarter/cmdCreate/readme.go

40 lines
816 B
Go
Raw Normal View History

2023-06-21 11:50:12 -04:00
package cmdCreate
2023-06-17 14:17:02 -04:00
import (
"bufio"
"log"
"os"
"strings"
)
func CreateReadme(projectName, description, author, url string) bool {
file, err := os.Open("../readme.template")
if err != nil {
log.Fatal(err)
}
defer file.Close()
template := ""
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
line = strings.Replace(line, "<project_name>", projectName, -1)
line = strings.Replace(line, "<description>", description, -1)
line = strings.Replace(line, "<author>", author, -1)
line = strings.Replace(line, "<gitea_project_url>", url, -1)
template += line + "\n"
}
readmeFile, err := os.Create("README.md")
if err != nil {
log.Fatal(err)
}
defer readmeFile.Close()
_, err = readmeFile.WriteString(template)
if err != nil {
log.Fatal(err)
}
return true
}