mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Improving createLicenseFile function
Also fixing typo in README example.
This commit is contained in:
parent
d811f40c6a
commit
9a8186dbb5
2 changed files with 17 additions and 14 deletions
|
@ -240,7 +240,7 @@ a custom license:
|
||||||
license:
|
license:
|
||||||
header: This file is part of {{ .appName }}.
|
header: This file is part of {{ .appName }}.
|
||||||
text: |
|
text: |
|
||||||
{{ .Copyright }}
|
{{ .copyright }}
|
||||||
|
|
||||||
This is my license. There are many like it, but this one is mine.
|
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
|
My license is my best friend. It is my life. I must master it as I must
|
||||||
|
|
|
@ -88,6 +88,10 @@ func initializePath(path string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createLicenseFile() {
|
func createLicenseFile() {
|
||||||
|
lic := getLicense()
|
||||||
|
|
||||||
|
// Don't bother writing a LICENSE file if there is no text.
|
||||||
|
if lic.Text != "" {
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
|
|
||||||
// Try to remove the email address, if any
|
// Try to remove the email address, if any
|
||||||
|
@ -95,13 +99,12 @@ func createLicenseFile() {
|
||||||
|
|
||||||
data["appName"] = projectName()
|
data["appName"] = projectName()
|
||||||
|
|
||||||
// Get license and generate the template from text and data.
|
// Generate license template from text and data.
|
||||||
lic := getLicense()
|
|
||||||
r, _ := templateToReader(lic.Text, data)
|
r, _ := templateToReader(lic.Text, data)
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(r)
|
buf.ReadFrom(r)
|
||||||
if template := buf.String(); template != "" {
|
|
||||||
err := writeTemplateToFile(ProjectPath(), "LICENSE", template, data)
|
err := writeTemplateToFile(ProjectPath(), "LICENSE", buf.String(), data)
|
||||||
_ = err
|
_ = err
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// er(err)
|
// er(err)
|
||||||
|
|
Loading…
Reference in a new issue