go-KodeStarter/cmdCreate
2023-06-21 11:50:12 -04:00
..
create.go ajout config.yml 2023-06-21 11:50:12 -04:00
readme.go ajout config.yml 2023-06-21 11:50:12 -04:00

package cmdCreate

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
}