From 821543bdaadfad72e85fafe7d77e54c3686d0827 Mon Sep 17 00:00:00 2001 From: Ian Walter Date: Thu, 31 Mar 2016 14:52:16 -0400 Subject: [PATCH] Improving createLicenseFile function Also fixing typo in README example. --- README.md | 2 +- cobra/cmd/init.go | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cb336343..043cdb53 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ a custom license: license: header: This file is part of {{ .appName }}. text: | - {{ .Copyright }} + {{ .copyright }} This is my license. There are many like it, but this one is mine. My license is my best friend. It is my life. I must master it as I must diff --git a/cobra/cmd/init.go b/cobra/cmd/init.go index 811e4264..b5e77ea0 100644 --- a/cobra/cmd/init.go +++ b/cobra/cmd/init.go @@ -88,20 +88,23 @@ func initializePath(path string) { } func createLicenseFile() { - data := make(map[string]interface{}) - - // Try to remove the email address, if any - data["copyright"] = strings.Split(copyrightLine(), " <")[0] - - data["appName"] = projectName() - - // Get license and generate the template from text and data. lic := getLicense() - r, _ := templateToReader(lic.Text, data) - buf := new(bytes.Buffer) - buf.ReadFrom(r) - if template := buf.String(); template != "" { - err := writeTemplateToFile(ProjectPath(), "LICENSE", template, data) + + // Don't bother writing a LICENSE file if there is no text. + if lic.Text != "" { + data := make(map[string]interface{}) + + // Try to remove the email address, if any + data["copyright"] = strings.Split(copyrightLine(), " <")[0] + + data["appName"] = projectName() + + // Generate license template from text and data. + r, _ := templateToReader(lic.Text, data) + buf := new(bytes.Buffer) + buf.ReadFrom(r) + + err := writeTemplateToFile(ProjectPath(), "LICENSE", buf.String(), data) _ = err // if err != nil { // er(err)