Repository: raviqqe/muffet
Pull request #109 (2020-09-27 03:24:05)

Fix default values in help

codecov[bot]: # [Codecov](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=h1) Report
> Merging [#109](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=desc) into [master](https://codecov.io/gh/raviqqe/muffet/commit/b85150ebbf2c291d4609a13cf66a75819c105966?el=desc) will **decrease** coverage by `1.05%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/raviqqe/muffet/pull/109/graphs/tree.svg?width=650&height=150&src=pr&token=qXJG42bGNw)](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #109      +/-   ##
==========================================
- Coverage   78.77%   77.71%   -1.06%     
==========================================
  Files          21       21              
  Lines         358      359       +1     
==========================================
- Hits          282      279       -3     
- Misses         63       66       +3     
- Partials       13       14       +1     
```


| [Impacted Files](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [throttled\_http\_client.go](https://codecov.io/gh/raviqqe/muffet/pull/109/diff?src=pr&el=tree#diff-dGhyb3R0bGVkX2h0dHBfY2xpZW50Lmdv) | `100.00% <ø> (ø)` | |
| [arguments.go](https://codecov.io/gh/raviqqe/muffet/pull/109/diff?src=pr&el=tree#diff-YXJndW1lbnRzLmdv) | `100.00% <100.00%> (ø)` | |
| [command.go](https://codecov.io/gh/raviqqe/muffet/pull/109/diff?src=pr&el=tree#diff-Y29tbWFuZC5nbw==) | `77.14% <100.00%> (ø)` | |
| [cache.go](https://codecov.io/gh/raviqqe/muffet/pull/109/diff?src=pr&el=tree#diff-Y2FjaGUuZ28=) | `66.66% <0.00%> (-33.34%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=footer). Last update [b85150e...1a8435b](https://codecov.io/gh/raviqqe/muffet/pull/109?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/arguments.go b/arguments.go
index c537acd..7cff387 100644
--- a/arguments.go
+++ b/arguments.go
@@ -1,8 +1,8 @@
 package main
 
 import (
+	"bytes"
 	"errors"
-	"io"
 	"regexp"
 	"strings"
 
@@ -61,11 +61,17 @@ func getArguments(ss []string) (*arguments, error) {
 	return &args, nil
 }
 
-func printHelp(w io.Writer) {
+func help() string {
 	p := flags.NewParser(&arguments{}, flags.PassDoubleDash)
 	p.Usage = "[options] <url>"
 
-	p.WriteHelp(w)
+	// Parse() is run here to show default values in help.
+	// This seems to be a bug in go-flags.
+	p.Parse() // nolint:errcheck
+
+	b := &bytes.Buffer{}
+	p.WriteHelp(b)
+	return b.String()
 }
 
 func compileRegexps(regexps []string) ([]*regexp.Regexp, error) {
diff --git a/command.go b/command.go
index 3111a60..59f6a5c 100644
--- a/command.go
+++ b/command.go
@@ -34,7 +34,7 @@ func (c *command) runWithError(ss []string) (bool, error) {
 	if err != nil {
 		return false, err
 	} else if args.Help {
-		printHelp(c.stdout)
+		c.print(help())
 		return true, nil
 	} else if args.Version {
 		c.print(version)
diff --git a/configuration.go b/configuration.go
index 61f767e..856bf56 100644
--- a/configuration.go
+++ b/configuration.go
@@ -3,9 +3,8 @@ package main
 import "time"
 
 const (
-	version               = "2.0.1"
-	agentName             = "muffet"
-	concurrency           = 1024
-	tcpTimeout            = time.Minute
-	defaultMaxConnections = 512
+	version     = "2.0.2"
+	agentName   = "muffet"
+	concurrency = 1024
+	tcpTimeout  = time.Minute
 )
diff --git a/throttled_http_client.go b/throttled_http_client.go
index f80d5b2..39e63f1 100644
--- a/throttled_http_client.go
+++ b/throttled_http_client.go
@@ -8,10 +8,6 @@ type throttledHTTPClient struct {
 }
 
 func newThrottledHTTPClient(c httpClient, maxConnections int) httpClient {
-	if maxConnections < 1 {
-		maxConnections = defaultMaxConnections
-	}
-
 	return &throttledHTTPClient{c, newSemaphore(maxConnections)}
 }
 


Test patch:
diff --git a/.snapshots/TestPrintHelp b/.snapshots/TestHelp
similarity index 82%
rename from .snapshots/TestPrintHelp
rename to .snapshots/TestHelp
index 331fe92..244fc99 100644
--- a/.snapshots/TestPrintHelp
+++ b/.snapshots/TestHelp
@@ -2,17 +2,21 @@ Usage:
   muffet.test [options] <url>
 
 Application Options:
-  -b, --buffer-size=              HTTP response buffer size in bytes
-  -c, --max-connections=          Maximum number of HTTP connections
+  -b, --buffer-size=              HTTP response buffer size in bytes (default:
+                                  4096)
+  -c, --max-connections=          Maximum number of HTTP connections (default:
+                                  512)
       --max-connections-per-host= Maximum number of HTTP connections per host
+                                  (default: 512)
   -e, --exclude=                  Exclude URLs matched with given regular
                                   expressions
       --follow-robots-txt         Follow robots.txt when scraping pages
       --follow-sitemap-xml        Scrape only pages listed in sitemap.xml
       --header=                   Custom headers
   -f, --ignore-fragments          Ignore URL fragments
-  -r, --max-redirections=         Maximum number of redirections
+  -r, --max-redirections=         Maximum number of redirections (default: 64)
   -t, --timeout=                  Timeout for HTTP requests in seconds
+                                  (default: 10)
   -v, --verbose                   Show successful results too
       --skip-tls-verification     Skip TLS certificate verification
       --one-page-only             Only check links found in the given URL
diff --git a/arguments_test.go b/arguments_test.go
index 60a3973..2ba123e 100644
--- a/arguments_test.go
+++ b/arguments_test.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"bytes"
 	"testing"
 
 	"github.com/bradleyjkemp/cupaloy"
@@ -60,10 +59,8 @@ func TestGetArgumentsError(t *testing.T) {
 	}
 }
 
-func TestPrintHelp(t *testing.T) {
-	b := &bytes.Buffer{}
-	printHelp(b)
-	cupaloy.SnapshotT(t, b.String())
+func TestHelp(t *testing.T) {
+	cupaloy.SnapshotT(t, help())
 }
 
 func TestParseHeaders(t *testing.T) {
diff --git a/throttled_http_client_test.go b/throttled_http_client_test.go
deleted file mode 100644
index 50afee3..0000000
--- a/throttled_http_client_test.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package main
-
-import "testing"
-
-func TestNewThrottledHTTPClientHandleInvalidConnectionsOptionGracefully(t *testing.T) {
-	newThrottledHTTPClient(nil, -1)
-}