Skip to content

Commit

Permalink
Fix default values in help (#109)
Browse files Browse the repository at this point in the history
* Fix default values in help

* Remove graceful handling of invalid argument in throttled http client

* Bump version

* Replace printHelp function

* Remove unused constant

* Ignore errcheck
  • Loading branch information
raviqqe authored Sep 27, 2020
1 parent b85150e commit faf729a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
10 changes: 7 additions & 3 deletions .snapshots/TestPrintHelp → .snapshots/TestHelp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions arguments.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"bytes"
"errors"
"io"
"regexp"
"strings"

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 2 additions & 5 deletions arguments_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bytes"
"testing"

"github.com/bradleyjkemp/cupaloy"
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 0 additions & 4 deletions throttled_http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ type throttledHTTPClient struct {
}

func newThrottledHTTPClient(c httpClient, maxConnections int) httpClient {
if maxConnections < 1 {
maxConnections = defaultMaxConnections
}

return &throttledHTTPClient{c, newSemaphore(maxConnections)}
}

Expand Down
7 changes: 0 additions & 7 deletions throttled_http_client_test.go

This file was deleted.

0 comments on commit faf729a

Please sign in to comment.