diff --git a/examples/markdown.feature b/examples/markdown.feature index 06da6f4..838a707 100644 --- a/examples/markdown.feature +++ b/examples/markdown.feature @@ -68,3 +68,15 @@ Feature: Markdown Then the exit status should be 1 And the stderr should contain "OK" And the stderr should contain "ERROR" + + Scenario: Check 2 markdown files + Given a file named "foo.md" with: + """ + [Google](https://google.com) + """ + And a file named "bar.md" with: + """ + [Yahoo](https://yahoo.com) + """ + When I successfully run `linkcheck foo.md bar.md` + Then the stdout should contain exactly "" diff --git a/main.go b/main.go index 821a5c8..d87cf86 100644 --- a/main.go +++ b/main.go @@ -21,22 +21,43 @@ func main() { }() args := getArgs() + fs := args[""].([]string) + bs := make(chan bool, len(fs)) + c := newURLChecker(5*time.Second, args["--verbose"].(bool)) + + for _, f := range fs { + go func(f string) { + bs <- checkFile(c, f) + }(f) + } + + ok := true + + for i := 0; i < len(fs); i++ { + ok = <-bs && ok + } + + if !ok { + os.Exit(1) + } +} - bs, err := ioutil.ReadFile(args[""].(string)) +func checkFile(c urlChecker, f string) bool { + bs, err := ioutil.ReadFile(f) if err != nil { - panic(err) + printToStderr(err.Error()) + return false } n, err := html.Parse(strings.NewReader(mark.Render(string(bs)))) if err != nil { - panic(err) + printToStderr(err.Error()) + return false } - if !newURLChecker(5*time.Second, args["--verbose"].(bool)).CheckMany(extractURLs(n)) { - os.Exit(1) - } + return c.CheckMany(extractURLs(n)) } func extractURLs(n *html.Node) []string { @@ -75,7 +96,7 @@ func getArgs() map[string]interface{} { usage := `Link checker for Markdown and HTML Usage: - linkcheck [-v] + linkcheck [-v] ... Options: -v, --verbose Be verbose`