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
}
