summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/cobra/cobra/cmd/licenses.go')
-rw-r--r--vendor/github.com/spf13/cobra/cobra/cmd/licenses.go109
1 files changed, 74 insertions, 35 deletions
diff --git a/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go b/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
index 5b3cb7293..d73e6fb35 100644
--- a/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
+++ b/vendor/github.com/spf13/cobra/cobra/cmd/licenses.go
@@ -15,13 +15,18 @@
package cmd
-import "strings"
+import (
+ "strings"
+ "time"
-//Licenses contains all possible licenses a user can chose from
-var Licenses map[string]License
+ "github.com/spf13/viper"
+)
-//License represents a software license agreement, containing the Name of
-// the license, its possible matches (on the command line as given to cobra)
+// Licenses contains all possible licenses a user can choose from.
+var Licenses = make(map[string]License)
+
+// License represents a software license agreement, containing the Name of
+// the license, its possible matches (on the command line as given to cobra),
// the header to be used with each file on the file's creating, and the text
// of the license
type License struct {
@@ -31,45 +36,79 @@ type License struct {
Header string // License header for source files
}
-// given a license name (in), try to match the license indicated
-func matchLicense(in string) string {
- for key, lic := range Licenses {
- for _, match := range lic.PossibleMatches {
- if strings.EqualFold(in, match) {
- return key
- }
- }
- }
- return ""
-}
-
func init() {
- Licenses = make(map[string]License)
-
// Allows a user to not use a license.
Licenses["none"] = License{"None", []string{"none", "false"}, "", ""}
- // Allows a user to use config for a custom license.
- Licenses["custom"] = License{"Custom", []string{}, "", ""}
-
initApache2()
-
initMit()
-
initBsdClause3()
-
initBsdClause2()
-
initGpl2()
-
initGpl3()
+ initLgpl()
+ initAgpl()
+}
- // Licenses["apache20"] = License{
- // Name: "Apache 2.0",
- // PossibleMatches: []string{"apache", "apache20", ""},
- // Header: `
- // `,
- // Text: `
- // `,
- // }
+// getLicense returns license specified by user in flag or in config.
+// If user didn't specify the license, it returns Apache License 2.0.
+//
+// TODO: Inspect project for existing license
+func getLicense() License {
+ // If explicitly flagged, use that.
+ if userLicense != "" {
+ return findLicense(userLicense)
+ }
+
+ // If user wants to have custom license, use that.
+ if viper.IsSet("license.header") || viper.IsSet("license.text") {
+ return License{Header: viper.GetString("license.header"),
+ Text: "license.text"}
+ }
+
+ // If user wants to have built-in license, use that.
+ if viper.IsSet("license") {
+ return findLicense(viper.GetString("license"))
+ }
+
+ // If user didn't set any license, use Apache 2.0 by default.
+ return Licenses["apache"]
+}
+
+func copyrightLine() string {
+ author := viper.GetString("author")
+ year := time.Now().Format("2006")
+
+ return "Copyright © " + year + " " + author
+}
+
+// findLicense looks for License object of built-in licenses.
+// If it didn't find license, then the app will be terminated and
+// error will be printed.
+func findLicense(name string) License {
+ found := matchLicense(name)
+ if found == "" {
+ er("unknown license: " + name)
+ }
+ return Licenses[found]
+}
+
+// matchLicense compares the given a license name
+// to PossibleMatches of all built-in licenses.
+// It returns blank string, if name is blank string or it didn't find
+// then appropriate match to name.
+func matchLicense(name string) string {
+ if name == "" {
+ return ""
+ }
+
+ for key, lic := range Licenses {
+ for _, match := range lic.PossibleMatches {
+ if strings.EqualFold(name, match) {
+ return key
+ }
+ }
+ }
+
+ return ""
}