Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jun 24, 2017
1 parent b3bdf81 commit b79a358
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,40 @@ var RootCmd = &cobra.Command{
fmt.Println(err)
os.Exit(1)
}
var checks = sh.Checkers()
for _, file := range files {
if ignore(ignores, file) {
status.Ignore(file)
continue
if err := check(file); err != nil {
fail = true
}
var errors []error
for _, check := range checks {
if err := check.Check(file); err != nil {
errors = append(errors, err)
}
}
if len(errors) == 0 {
status.Success(file)
continue
}
status.Fail(file)
for _, err := range errors {
fmt.Println(err)
}
fmt.Printf("\n\n")
fail = true
}

if fail {
fmt.Printf("\n\nsome checks failed. check logs above\n")
fmt.Printf("\nsome checks failed. check output above.\n")
os.Exit(1)
}
},
}

func check(file string) error {
if ignore(ignores, file) {
status.Ignore(file)
return nil
}
var errors []error
for _, check := range sh.Checkers() {
if err := check.Check(file); err != nil {
errors = append(errors, err)
}
}
if len(errors) == 0 {
status.Success(file)
return nil
}
status.Fail(file)
for _, err := range errors {
fmt.Println(err)
}
return fmt.Errorf("check failed")
}

func ignore(patterns []string, file string) bool {
for _, pattern := range patterns {
if ok, err := zglob.Match(pattern, file); ok && err == nil {
Expand Down

0 comments on commit b79a358

Please sign in to comment.