Browse Source

Add timeout option

renovate/configure
Yota Toyama 8 years ago
parent
commit
67a368cda7
  1. 25
      arguments.go
  2. 8
      examples/markdown.feature
  3. 7
      main.go

25
arguments.go

@ -1,17 +1,24 @@
package main package main
import "github.com/docopt/docopt-go" import (
"strconv"
"time"
"github.com/docopt/docopt-go"
)
const usage = `Link checker for Markdown and HTML const usage = `Link checker for Markdown and HTML
Usage: Usage:
linkcheck [-v] <filenames>... linkcheck [-t <timeout>] [-v] <filenames>...
Options: Options:
-v, --verbose Be verbose` -v, --verbose Be verbose
-t, --timeout <timeout> Set timeout for HTTP requests in seconds [default: 5]`
type arguments struct { type arguments struct {
filenames []string filenames []string
timeout time.Duration
verbose bool verbose bool
} }
@ -22,5 +29,15 @@ func getArgs() (arguments, error) {
return arguments{}, err return arguments{}, err
} }
return arguments{args["<filenames>"].([]string), args["--verbose"].(bool)}, nil f, err := strconv.ParseFloat(args["--timeout"].(string), 64)
if err != nil {
return arguments{}, err
}
return arguments{
args["<filenames>"].([]string),
time.Duration(f) * time.Second,
args["--verbose"].(bool),
}, nil
} }

8
examples/markdown.feature

@ -104,3 +104,11 @@ Feature: Markdown
""" """
When I successfully run `sh foo.sh` When I successfully run `sh foo.sh`
Then the stdout should contain exactly "5" Then the stdout should contain exactly "5"
Scenario: Check a markdown file which contains a live link with timeout
Given a file named "foo.md" with:
"""
[Google](https://google.com)
"""
When I successfully run `linkcheck --timeout 10 foo.md`
Then the stdout should contain exactly ""

7
main.go

@ -1,9 +1,6 @@
package main package main
import ( import "os"
"os"
"time"
)
func main() { func main() {
args, err := getArgs() args, err := getArgs()
@ -15,7 +12,7 @@ func main() {
fs := args.filenames fs := args.filenames
rc := make(chan fileResult, len(fs)) rc := make(chan fileResult, len(fs))
c := newFileChecker(5 * time.Second) c := newFileChecker(args.timeout)
go c.CheckMany(fs, rc) go c.CheckMany(fs, rc)

Loading…
Cancel
Save