Auto generate full license text and embed
Display the licenses of all dependencies in a context menu suboptionpull/3/head
parent
d87c8153c7
commit
3083a4084f
@ -1,3 +1,4 @@
|
||||
bin/
|
||||
librnnoise.go
|
||||
version.go
|
||||
version.go
|
||||
licenses.go
|
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
out, _ := os.Create("licenses.go")
|
||||
out.Write([]byte("package main \n\nvar licenseString=`"))
|
||||
out.WriteString("LICENSES\n")
|
||||
out.WriteString("========\n")
|
||||
defer out.Close()
|
||||
filepath.Walk(cwd, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if strings.HasPrefix("LICENSE", info.Name()) {
|
||||
rel, err := filepath.Rel(cwd, path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
dir := filepath.Dir(rel)
|
||||
out.WriteString("FILES: " + dir + "\n")
|
||||
c, err := ioutil.ReadFile(path)
|
||||
str := string(c)
|
||||
str = strings.ReplaceAll(str, "`", "`"+" + \"`\" + `") // escape backticks in license text for go src
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
out.WriteString(str)
|
||||
out.WriteString("\n\n")
|
||||
|
||||
}
|
||||
return nil
|
||||
})
|
||||
out.Write([]byte("`\n"))
|
||||
}
|
Loading…
Reference in New Issue