vgo - generate license

This commit is contained in:
jharshman 2019-01-29 20:25:38 -08:00 committed by Steve Francia
parent abab9aa52a
commit 5b1685faaa
1 changed files with 31 additions and 2 deletions

View File

@ -60,10 +60,39 @@ func (p *Project) Create() error {
} }
// create license // create license
createLicenseFile(p.Legal, p.AbsolutePath) return createLicenseFile(p.Legal, p.AbsolutePath)
return nil
} }
func (p *Project) createLicenseFile() error {
data := map[string]interface{}{
"copyright": copyrightLine(),
}
licenseFile, err := os.Create(fmt.Sprintf("%s/LICENSE", p.AbsolutePath))
if err != nil {
return err
}
licenseTemplate := template.Must(template.New("license").Parse(p.Legal.Text))
return licenseTemplate.Execute(licenseFile, data)
}
//func createLicenseFile(license License, path string) {
// data := make(map[string]interface{})
// data["copyright"] = copyrightLine()
//
// // Generate license template from text and data.
// text, err := executeTemplate(license.Text, data)
// if err != nil {
// er(err)
// }
//
// // Write license text to LICENSE file.
// err = writeStringToFile(filepath.Join(path, "LICENSE"), text)
// if err != nil {
// er(err)
// }
//}
// NewProject returns Project with specified project name. // NewProject returns Project with specified project name.
func NewProject(projectName string) *Project { func NewProject(projectName string) *Project {
if projectName == "" { if projectName == "" {