From 9206202e1ee0b46330b03a279ca9db0e3eb7ed96 Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Tue, 9 Feb 2016 22:49:04 +0900 Subject: [PATCH] #80 check for multiple license file types --- check/license.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/check/license.go b/check/license.go index 7787d65..728313b 100644 --- a/check/license.go +++ b/check/license.go @@ -21,16 +21,32 @@ func (g License) Weight() float64 { return .10 } +// thank you https://github.com/ryanuber/go-license +var licenses = []string{ + "license", "license.txt", "license.md", + "copying", "copying.txt", "copying.md", + "unlicense", +} + // Percentage returns 0 if no LICENSE, 1 if LICENSE func (g License) Percentage() (float64, []FileSummary, error) { - cmd := exec.Command("find", g.Dir, "-maxdepth", "1", "-type", "f", "-name", "LICENSE*") - var out bytes.Buffer - cmd.Stdout = &out - err := cmd.Run() - if err != nil { - return 0.0, []FileSummary{}, err + var exists bool + for _, license := range licenses { + cmd := exec.Command("find", g.Dir, "-maxdepth", "1", "-type", "f", "-iname", license) + var out bytes.Buffer + cmd.Stdout = &out + err := cmd.Run() + if err != nil { + return 0.0, []FileSummary{}, err + } + if out.String() == "" { + continue + } + exists = true + break } - if out.String() == "" { + + if !exists { return 0.0, []FileSummary{{"", "http://choosealicense.com/", []Error{}}}, nil }