From 5b1685faaa2b08aec83e0ea49d00e0a49735a773 Mon Sep 17 00:00:00 2001 From: jharshman Date: Tue, 29 Jan 2019 20:25:38 -0800 Subject: [PATCH] vgo - generate license --- cobra/cmd/project.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cobra/cmd/project.go b/cobra/cmd/project.go index cf66e83..ab34983 100644 --- a/cobra/cmd/project.go +++ b/cobra/cmd/project.go @@ -60,10 +60,39 @@ func (p *Project) Create() error { } // create license - createLicenseFile(p.Legal, p.AbsolutePath) - return nil + return createLicenseFile(p.Legal, p.AbsolutePath) } +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. func NewProject(projectName string) *Project { if projectName == "" {