|
|
@ -21,22 +21,43 @@ func main() { |
|
|
}() |
|
|
}() |
|
|
|
|
|
|
|
|
args := getArgs() |
|
|
args := getArgs() |
|
|
|
|
|
fs := args["<filenames>"].([]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["<filename>"].(string)) |
|
|
func checkFile(c urlChecker, f string) bool { |
|
|
|
|
|
bs, err := ioutil.ReadFile(f) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(err) |
|
|
printToStderr(err.Error()) |
|
|
|
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n, err := html.Parse(strings.NewReader(mark.Render(string(bs)))) |
|
|
n, err := html.Parse(strings.NewReader(mark.Render(string(bs)))) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(err) |
|
|
printToStderr(err.Error()) |
|
|
|
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if !newURLChecker(5*time.Second, args["--verbose"].(bool)).CheckMany(extractURLs(n)) { |
|
|
return c.CheckMany(extractURLs(n)) |
|
|
os.Exit(1) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func extractURLs(n *html.Node) []string { |
|
|
func extractURLs(n *html.Node) []string { |
|
|
@ -75,7 +96,7 @@ func getArgs() map[string]interface{} { |
|
|
usage := `Link checker for Markdown and HTML |
|
|
usage := `Link checker for Markdown and HTML |
|
|
|
|
|
|
|
|
Usage: |
|
|
Usage: |
|
|
linkcheck [-v] <filename> |
|
|
linkcheck [-v] <filenames>... |
|
|
|
|
|
|
|
|
Options: |
|
|
Options: |
|
|
-v, --verbose Be verbose` |
|
|
-v, --verbose Be verbose` |
|
|
|