From ada5eb9754156767c6250a3be657d9120bf0d7d9 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Thu, 16 May 2019 20:27:05 -0700 Subject: [PATCH] Add config to prevent addition of copyright notice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some projects do not add copyright headers to the tops of their files. Right now you can specify `license: none` to prevent a license from being generated for the file. But you will still get a line like: `// Copyright © 2017 NAME HERE ` This change allows passing `author: none` to prevent that line from being generated. The change does not alter the defaults. However, it does slightly change the formatting templates to prevent the extraneous addition of newlines when an author or liciece line is not requested. --- cobra/README.md | 3 +++ cobra/cmd/add.go | 6 +++--- cobra/cmd/init.go | 12 ++++++------ cobra/cmd/licenses.go | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cobra/README.md b/cobra/README.md index 6054f95c..fad7c225 100644 --- a/cobra/README.md +++ b/cobra/README.md @@ -92,3 +92,6 @@ license: You can also use built-in licenses. For example, **GPLv2**, **GPLv3**, **LGPL**, **AGPL**, **MIT**, **2-Clause BSD** or **3-Clause BSD**. + +You can prevent the generation of the `// Copyright © 2015 AUTHOR ` line +at the top of the file by setting `author` to `none`. diff --git a/cobra/cmd/add.go b/cobra/cmd/add.go index fb22096a..80b59330 100644 --- a/cobra/cmd/add.go +++ b/cobra/cmd/add.go @@ -120,9 +120,9 @@ func validateCmdName(source string) string { } func createCmdFile(license License, path, cmdName string) { - template := `{{comment .copyright}} -{{if .license}}{{comment .license}}{{end}} - + template := `{{if .copyright}}{{comment .copyright}} +{{end}}{{if .license}}{{comment .license}} +{{end}} package {{.cmdPackage}} import ( diff --git a/cobra/cmd/init.go b/cobra/cmd/init.go index d65e6c8c..e2efd597 100644 --- a/cobra/cmd/init.go +++ b/cobra/cmd/init.go @@ -106,9 +106,9 @@ func createLicenseFile(license License, path string) { } func createMainFile(project *Project) { - mainTemplate := `{{ comment .copyright }} -{{if .license}}{{ comment .license }}{{end}} - + mainTemplate := `{{if .copyright}}{{comment .copyright}} +{{end}}{{if .license}}{{comment .license}} +{{end}} package main import "{{ .importpath }}" @@ -134,9 +134,9 @@ func main() { } func createRootCmdFile(project *Project) { - template := `{{comment .copyright}} -{{if .license}}{{comment .license}}{{end}} - + template := `{{if .copyright}}{{comment .copyright}} +{{end}}{{if .license}}{{comment .license}} +{{end}} package cmd import ( diff --git a/cobra/cmd/licenses.go b/cobra/cmd/licenses.go index a070134d..61b28dfa 100644 --- a/cobra/cmd/licenses.go +++ b/cobra/cmd/licenses.go @@ -77,6 +77,9 @@ func getLicense() License { func copyrightLine() string { author := viper.GetString("author") + if author == "none" { + return "" + } year := viper.GetString("year") // For tests. if year == "" {