diff --git a/check.go b/check.go index 54ca338..bf26ab1 100644 --- a/check.go +++ b/check.go @@ -8,10 +8,20 @@ import ( ) type Result struct { + Failures []Failure // XXX perhaps this is a list of the failed files and keywords? } -var ErrNotAllClear = fmt.Errorf("some keyword check failed validation") +type Failure struct { + Path string + Keyword string + Expected string + Got string +} + +func (f Failure) String() string { + return fmt.Sprintf("%q: keyword %q: expected %s; got %s", f.Path, f.Keyword, f.Expected, f.Got) +} func Check(root string, dh *DirectoryHierarchy) (*Result, error) { creator := dhCreator{DH: dh} @@ -25,7 +35,7 @@ func Check(root string, dh *DirectoryHierarchy) (*Result, error) { } sort.Sort(byPos(creator.DH.Entries)) - var failed bool + var result Result for _, e := range creator.DH.Entries { switch e.Type { case SpecialType: @@ -57,16 +67,11 @@ func Check(root string, dh *DirectoryHierarchy) (*Result, error) { return nil, err } if string(kv) != curKeyVal { - failed = true - fmt.Printf("%q: keyword %q: expected %s; got %s\n", e.Path(), kv.Keyword(), kv.Value(), KeyVal(curKeyVal).Value()) + failure := Failure{Path: e.Path(), Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()} + result.Failures = append(result.Failures, failure) } } } } - - if failed { - return nil, ErrNotAllClear - } - - return nil, nil + return &result, nil } diff --git a/cmd/gomtree/main.go b/cmd/gomtree/main.go index 347e383..f0c9e1b 100644 --- a/cmd/gomtree/main.go +++ b/cmd/gomtree/main.go @@ -98,8 +98,10 @@ func main() { isErr = true return } - if res != nil { - fmt.Printf("%#v\n", res) + if res != nil && len(res.Failures) > 0 { + for _, failure := range res.Failures { + fmt.Println(failure) + } } } }