diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4ccb0d68..66142e99 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,4 +24,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - run: npx markdown-link-check README.md + - uses: lycheeverse/lychee-action@v1 + with: + fail: true diff --git a/.snapshots/TestHelp b/.snapshots/TestHelp index bf1a382d..f09e95fe 100644 --- a/.snapshots/TestHelp +++ b/.snapshots/TestHelp @@ -20,6 +20,7 @@ Application Options: sitemap.xml --header=
... Custom headers -f, --ignore-fragments Ignore URL fragments + --format=[text|json|junit] Output format (default: text) --json Output results in JSON --experimental-verbose-json Include successful results in JSON --junit Output results as JUnit XML file diff --git a/arguments.go b/arguments.go index 5d88f5e8..5c93454d 100644 --- a/arguments.go +++ b/arguments.go @@ -19,7 +19,9 @@ type arguments struct { FollowRobotsTxt bool `long:"follow-robots-txt" description:"Follow robots.txt when scraping pages"` FollowSitemapXML bool `long:"follow-sitemap-xml" description:"Scrape only pages listed in sitemap.xml"` RawHeaders []string `long:"header" value-name:"
..." description:"Custom headers"` - IgnoreFragments bool `short:"f" long:"ignore-fragments" description:"Ignore URL fragments"` + // TODO Remove a short option. + IgnoreFragments bool `short:"f" long:"ignore-fragments" description:"Ignore URL fragments"` + Format string `long:"format" description:"Output format" default:"text" choice:"text" choice:"json" choice:"junit"` // TODO Merge text, JSON, and JUnit XML format options into --format. JSONOutput bool `long:"json" description:"Output results in JSON"` // TODO Integrate this option into --verbose. @@ -53,6 +55,8 @@ func getArguments(ss []string) (*arguments, error) { return nil, errors.New("invalid number of arguments") } + reconcileDeprecatedArguments(&args) + args.URL = ss[0] args.ExcludedPatterns, err = compileRegexps(args.RawExcludedPatterns) @@ -70,6 +74,10 @@ func getArguments(ss []string) (*arguments, error) { return nil, err } + if args.Format == "junit" && args.Verbose { + return nil, errors.New("verbose option not supported for JUnit output") + } + return &args, nil } @@ -116,3 +124,12 @@ func parseHeaders(headers []string) (map[string]string, error) { return m, nil } + +func reconcileDeprecatedArguments(args *arguments) { + if args.JSONOutput { + args.Format = "json" + args.Verbose = args.Verbose || args.VerboseJSON + } else if args.JUnitOutput { + args.Format = "junit" + } +} diff --git a/command.go b/command.go index f32a1be3..9dcee50a 100644 --- a/command.go +++ b/command.go @@ -41,13 +41,7 @@ func (c *command) runWithError(ss []string) (bool, error) { return true, nil } else if args.Version { c.print(version) - return err == nil, err - } else if args.JSONOutput && args.Verbose { - return false, errors.New("verbose option not supported for JSON output") - } else if args.JUnitOutput && args.Verbose { - return false, errors.New("verbose option not supported for JUnit output") - } else if args.JSONOutput && args.JUnitOutput { - return false, errors.New("JSON and JUnit output are mutually exclusive") + return true, nil } client := newRedirectHttpClient( @@ -115,9 +109,10 @@ func (c *command) runWithError(ss []string) (bool, error) { go checker.Check(p) - if args.JSONOutput { - return c.printResultsInJSON(checker.Results(), args.VerboseJSON) - } else if args.JUnitOutput { + switch args.Format { + case "json": + return c.printResultsInJSON(checker.Results(), args.Verbose) + case "junit": return c.printResultsInJUnitXML(checker.Results()) } diff --git a/command_test.go b/command_test.go index 828b503b..1995f9fc 100644 --- a/command_test.go +++ b/command_test.go @@ -270,17 +270,6 @@ func TestCommandIncludeSuccessfulPageInJSONOutputWhenRequested(t *testing.T) { assert.Equal(t, strings.TrimSpace(b.String()), "[{\"url\":\"\",\"links\":[]}]") } -func TestCommandFailWithVerboseAndJSONOptions(t *testing.T) { - b := &bytes.Buffer{} - - ok := newTestCommandWithStderr(b, nil).Run( - []string{"--json", "--verbose", "http://foo.com"}, - ) - - assert.False(t, ok) - cupaloy.SnapshotT(t, b.String()) -} - func TestCommandFailToRunWithJUnitOutput(t *testing.T) { b := &bytes.Buffer{} @@ -312,14 +301,3 @@ func TestCommandFailWithVerboseAndJUnitOptions(t *testing.T) { assert.False(t, ok) cupaloy.SnapshotT(t, b.String()) } - -func TestCommandFailWithJUnitAndJSONOptions(t *testing.T) { - b := &bytes.Buffer{} - - ok := newTestCommandWithStderr(b, nil).Run( - []string{"--json", "--junit", "http://foo.com"}, - ) - - assert.False(t, ok) - cupaloy.SnapshotT(t, b.String()) -}