failures not counted correctly in some cases.
Summary output added.
This commit is contained in:
@@ -6,7 +6,7 @@ func main() {
|
||||
module.GenerateLicenseNames()
|
||||
module.DumpOverview()
|
||||
|
||||
module.DumpText()
|
||||
module.DumpText(true)
|
||||
}
|
||||
|
||||
func truncateString(s string, length int) string {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -89,7 +90,11 @@ func NewModule(modules []ModuleDependency) *Module {
|
||||
if mod.Dir == "" {
|
||||
continue // Skip modules without local copies
|
||||
}
|
||||
license := module.findLicense(mod.Dir)
|
||||
license, err := module.findLicense(mod.Dir)
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %v", err)
|
||||
continue
|
||||
}
|
||||
module.Licenses[hash(license.Text)] = license
|
||||
dependency := NewDependency(mod.Path, mod.Version, !mod.Indirect, license)
|
||||
module.Dependencies = append(module.Dependencies, dependency)
|
||||
@@ -138,8 +143,11 @@ func (module Module) DumpOverview() {
|
||||
}
|
||||
}
|
||||
|
||||
func (module Module) DumpText() {
|
||||
func (module Module) DumpText(directOnly bool) {
|
||||
for _, dependency := range module.Dependencies {
|
||||
if directOnly && !dependency.Direct {
|
||||
continue
|
||||
}
|
||||
fmt.Println(strings.Repeat("=", 80))
|
||||
if dependency.Direct {
|
||||
fmt.Printf("Direct dependency")
|
||||
@@ -152,7 +160,7 @@ func (module Module) DumpText() {
|
||||
}
|
||||
}
|
||||
|
||||
func (module *Module) findLicense(dir string) *License {
|
||||
func (module *Module) findLicense(dir string) (*License, error) {
|
||||
licenseFiles := []string{
|
||||
"LICENSE",
|
||||
"LICENSE.txt",
|
||||
@@ -174,12 +182,12 @@ func (module *Module) findLicense(dir string) *License {
|
||||
hashcode := hash(content)
|
||||
license := module.Licenses[hashcode]
|
||||
if license != nil {
|
||||
return license
|
||||
return license, nil
|
||||
}
|
||||
return NewLicense(content)
|
||||
return NewLicense(content), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return nil, fmt.Errorf("No license found in '%s'", dir)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user