Skip to content

Commit 9a8186d

Browse files
Ian Walterspf13
authored andcommitted
Improving createLicenseFile function
Also fixing typo in README example.
1 parent d811f40 commit 9a8186d

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ a custom license:
240240
license:
241241
header: This file is part of {{ .appName }}.
242242
text: |
243-
{{ .Copyright }}
243+
{{ .copyright }}
244244
245245
This is my license. There are many like it, but this one is mine.
246246
My license is my best friend. It is my life. I must master it as I must

cobra/cmd/init.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,23 @@ func initializePath(path string) {
8888
}
8989

9090
func createLicenseFile() {
91-
data := make(map[string]interface{})
91+
lic := getLicense()
9292

93-
// Try to remove the email address, if any
94-
data["copyright"] = strings.Split(copyrightLine(), " <")[0]
93+
// Don't bother writing a LICENSE file if there is no text.
94+
if lic.Text != "" {
95+
data := make(map[string]interface{})
9596

96-
data["appName"] = projectName()
97+
// Try to remove the email address, if any
98+
data["copyright"] = strings.Split(copyrightLine(), " <")[0]
9799

98-
// Get license and generate the template from text and data.
99-
lic := getLicense()
100-
r, _ := templateToReader(lic.Text, data)
101-
buf := new(bytes.Buffer)
102-
buf.ReadFrom(r)
103-
if template := buf.String(); template != "" {
104-
err := writeTemplateToFile(ProjectPath(), "LICENSE", template, data)
100+
data["appName"] = projectName()
101+
102+
// Generate license template from text and data.
103+
r, _ := templateToReader(lic.Text, data)
104+
buf := new(bytes.Buffer)
105+
buf.ReadFrom(r)
106+
107+
err := writeTemplateToFile(ProjectPath(), "LICENSE", buf.String(), data)
105108
_ = err
106109
// if err != nil {
107110
// er(err)

0 commit comments

Comments
 (0)