From ae7fb6452b8242c137a4551ec0485c05fc519f13 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Sat, 18 Nov 2017 02:15:04 +0900 Subject: [PATCH] Add verbose option --- examples/markdown.feature | 16 ++++++++++++++++ main.go | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/markdown.feature b/examples/markdown.feature index 46afc95..e896551 100644 --- a/examples/markdown.feature +++ b/examples/markdown.feature @@ -41,3 +41,19 @@ Feature: Markdown When I run `linkcheck foo.md` Then the exit status should be 1 And the stderr should contain "ERROR" + + Scenario: Check a markdown file which contains a live link in verbose mode + Given a file named "foo.md" with: + """ + [Google](https://google.com) + """ + When I successfully run `linkcheck -v foo.md` + Then the stderr should contain "OK" + + Scenario: Check a markdown file which contains a live link in verbose mode with a long option + Given a file named "foo.md" with: + """ + [Google](https://google.com) + """ + When I successfully run `linkcheck --verbose foo.md` + Then the stderr should contain "OK" diff --git a/main.go b/main.go index aeb3d49..4974299 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,8 @@ func main() { if _, err := http.Get(s); err != nil { printToStderr(color.New(color.FgRed).SprintFunc()("ERROR") + "\t" + colored + "\t" + err.Error()) ok = false + } else if err == nil && args["--verbose"].(bool) { + printToStderr(color.New(color.FgGreen).SprintFunc()("OK") + "\t" + colored) } } @@ -88,7 +90,10 @@ func getArgs() map[string]interface{} { usage := `Link checker for Markdown and HTML Usage: - linkcheck ` + linkcheck [-v] + +Options: + -v, --verbose Be verbose` args, err := docopt.Parse(usage, nil, true, "linkcheck", true)