Skip to content
Myr

cmd: Move some license functions from helpers.go to licenses.go

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 28fe9aa · Browse files · 2 files+59 added−57 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+59 added−57 removed

  • other:+59 added−57 removed

2 files+59 added−57 removed

modified:cobra/cmd/helpers.go-44 removed
19 unmodified lines
20 "os"21 "path/filepath"22 "strings"23 "text/template"24 "time"2526 "github.com/spf13/viper"24)2526// var BaseDir = ""27// var AppName = ""
265 unmodified lines
293 _, err = io.Copy(file, r)294 return295}296300func getLicense() License {301 l := whichLicense()302 if l != "" {303 if x, ok := Licenses[l]; ok {304 return x305 }306 }307308 return Licenses["apache"]309}310311func whichLicense() string {312 // if explicitly flagged, use that313 if userLicense != "" {314 return matchLicense(userLicense)315 }316317 // if already present in the project, use that318 // TODO: Inspect project for existing license319320 // default to viper's setting321322 if viper.IsSet("license.header") || viper.IsSet("license.text") {323 if custom, ok := Licenses["custom"]; ok {324 custom.Header = viper.GetString("license.header")325 custom.Text = viper.GetString("license.text")326 Licenses["custom"] = custom327 return "custom"328 }329 }330331 return matchLicense(viper.GetString("license"))332}333334func copyrightLine() string {335 author := viper.GetString("author")336 year := time.Now().Format("2006")337338 return "Copyright © " + year + " " + author339}340297func commentifyString(in string) string {298 var newlines []string299 lines := strings.Split(in, "\n")300 for _, x := range lines {
12 unmodified lines
modified:cobra/cmd/licenses.go+59 added-13 removed
13 unmodified lines
14// Parts inspired by https://github.com/ryanuber/go-license1516package cmd1718import "strings"18import (19 "strings"20 "time"2122 "github.com/spf13/viper"23)2425//Licenses contains all possible licenses a user can chose from26var Licenses map[string]License2728//License represents a software license agreement, containing the Name of
6 unmodified lines
35 Text string // License text data36 Header string // License header for source files37}3834// given a license name (in), try to match the license indicated35func matchLicense(in string) string {36 for key, lic := range Licenses {37 for _, match := range lic.PossibleMatches {38 if strings.EqualFold(in, match) {39 return key40 }41 }42 }43 return ""44}4539func init() {40 Licenses = make(map[string]License)4142 // Allows a user to not use a license.
22 unmodified lines
65 // Text: `66 // `,67 // }68}6970func getLicense() License {71 l := whichLicense()72 if l != "" {73 if x, ok := Licenses[l]; ok {74 return x75 }76 }7778 return Licenses["apache"]79}8081func whichLicense() string {82 // if explicitly flagged, use that83 if userLicense != "" {84 return matchLicense(userLicense)85 }8687 // if already present in the project, use that88 // TODO: Inspect project for existing license8990 // default to viper's setting9192 if viper.IsSet("license.header") || viper.IsSet("license.text") {93 if custom, ok := Licenses["custom"]; ok {94 custom.Header = viper.GetString("license.header")95 custom.Text = viper.GetString("license.text")96 Licenses["custom"] = custom97 return "custom"98 }99 }100101 return matchLicense(viper.GetString("license"))102}103104func copyrightLine() string {105 author := viper.GetString("author")106 year := time.Now().Format("2006")107108 return "Copyright © " + year + " " + author109}110111// given a license name (in), try to match the license indicated112func matchLicense(in string) string {113 for key, lic := range Licenses {114 for _, match := range lic.PossibleMatches {115 if strings.EqualFold(in, match) {116 return key117 }118 }119 }120 return ""121}