1
0

Compare commits

...

3 Commits

3 changed files with 21 additions and 6 deletions

13
main.go
View File

@ -1,9 +1,11 @@
package main package main
import ( import (
"embed"
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/fs"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@ -17,6 +19,9 @@ type LicensingData struct {
Year int Year int
} }
//go:embed all:templates
var Templates embed.FS
var GitConfigError = errors.New("Can't read Git config") var GitConfigError = errors.New("Can't read Git config")
var NotSupportedError = errors.New("Not supported license") var NotSupportedError = errors.New("Not supported license")
@ -36,11 +41,7 @@ func getGitUserData() (string, string, error) {
} }
func getTemplateList() []string { func getTemplateList() []string {
d, err := os.Open("templates") files, err := fs.ReadDir(Templates, "templates")
if err != nil {
panic(err)
}
files, err := d.Readdir(0)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -60,7 +61,7 @@ func listTemplates() {
func genLicense(lcnsName string, lcnsData LicensingData, outFileName string) error { func genLicense(lcnsName string, lcnsData LicensingData, outFileName string) error {
tmplFile := "templates/" + lcnsName + ".tmpl" tmplFile := "templates/" + lcnsName + ".tmpl"
tmpl, err := template.ParseFiles(tmplFile) tmpl, err := template.ParseFS(Templates, tmplFile)
if err != nil { if err != nil {
return NotSupportedError return NotSupportedError
} }

7
templates/ISC.tmpl Normal file
View File

@ -0,0 +1,7 @@
ISC License
Copyright {{.Year}} {{.AuthorName}}
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

7
templates/MIT.tmpl Normal file
View File

@ -0,0 +1,7 @@
Copyright {{.Year}} {{.AuthorName}}
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.