Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ builds:

homebrew_casks:
- name: dead
binary: dead
binaries:
- dead
directory: Casks
description: A dead simple link checker, supporting multiple formats
homepage: https://github.com/FollowTheProcess/dead
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.25

require (
github.com/rogpeppe/go-internal v1.14.1
go.followtheprocess.codes/cli v0.16.0
go.followtheprocess.codes/cli v0.17.0
go.followtheprocess.codes/hue v1.0.0
go.followtheprocess.codes/log v1.2.0
go.followtheprocess.codes/msg v1.9.2
Expand All @@ -13,7 +13,7 @@ require (
)

require (
golang.org/x/sys v0.37.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/tools v0.38.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
go.followtheprocess.codes/cli v0.16.0 h1:fzuJQifIdZA8gPAOKMklJ2jdp5UaGbBXH8txzoUAN6E=
go.followtheprocess.codes/cli v0.16.0/go.mod h1:3zCwrPo0bbuFbLVVOdkLgcMLL6oEmErx0vYu8RfKfao=
go.followtheprocess.codes/cli v0.17.0 h1:wAahiHmRUGEZ72jXOrZw5mPzU5h5qYDzqEt39zaW684=
go.followtheprocess.codes/cli v0.17.0/go.mod h1:vNqup3nFyWFAqJdZyL8s29ES/dt2FOJsvJ7kFH+CgWc=
go.followtheprocess.codes/hue v1.0.0 h1:0fYXAGR1o+w7Vja+Q+iVtqeEP3/CE6ET/pniyl8e9yo=
go.followtheprocess.codes/hue v1.0.0/go.mod h1:gSn5xK6KJapih+eFgQk3woo1qg3/rx9XSrAanUIuDr8=
go.followtheprocess.codes/log v1.2.0 h1:23MY3BRVe9fr+mFCofVixv//RcmaMVCk56MZY/aRWW8=
Expand All @@ -14,8 +14,8 @@ go.followtheprocess.codes/spin v0.3.1 h1:1CI1cz2I51ih1BZ98LPZKr/BujzjBg9ec954+x6
go.followtheprocess.codes/spin v0.3.1/go.mod h1:fBVKIvKiOY0UegufW0ALoHMmq0Ffi76ACxWP88WXhWY=
go.followtheprocess.codes/test v1.0.0 h1:5m2MPOQpohDC9pf5hgqpH+4ldJP5g+YFVdoGQY41aeU=
go.followtheprocess.codes/test v1.0.0/go.mod h1:e627pR8IhsTV/RfuP/WKYjyL0BmuIbmaw2iKlQBCWrY=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"runtime"

"go.followtheprocess.codes/cli"
"go.followtheprocess.codes/cli/flag"
"go.followtheprocess.codes/dead/internal/dead"
)

Expand Down Expand Up @@ -32,8 +33,8 @@ func check() (*cli.Command, error) {
return cli.New(
"check",
cli.Short("Check a file or files in a directory (recursively) for dead links"),
cli.RequiredArg("path", "Path to the file or directory to scan"),
cli.Flag(&options.Debug, "debug", cli.NoShortHand, false, "Enable debug logging"),
cli.Arg(&options.Path, "path", "Path to the file or directory to scan"),
cli.Flag(&options.Debug, "debug", flag.NoShortHand, false, "Enable debug logging"),
cli.Flag(&options.Timeout, "timeout", 't', dead.DefaultOverallTimeout, "Timeout for the entire operation"),
cli.Flag(
&options.RequestTimeout,
Expand All @@ -49,9 +50,9 @@ func check() (*cli.Command, error) {
runtime.NumCPU(),
"Number of goroutines available for checking",
),
cli.Run(func(cmd *cli.Command, args []string) error {
cli.Run(func(cmd *cli.Command) error {
dead := dead.New(cmd.Stdout(), cmd.Stderr(), options.Debug, version)
return dead.Check(cmd.Arg("path"), options)
return dead.Check(options)
}),
)
}
15 changes: 8 additions & 7 deletions internal/dead/dead.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func New(stdout, stderr io.Writer, debug bool, version string) Dead {

// CheckOptions are the flags passed to the check subcommand.
type CheckOptions struct {
Path string // Path to check
Debug bool // Enable verbose logging
RequestTimeout time.Duration // Per request timeout
Timeout time.Duration // Timeout for the whole operation
Expand All @@ -91,7 +92,7 @@ type CheckResult struct {
}

// Check is the entry point for the `dead check` subcommand.
func (d Dead) Check(path string, options CheckOptions) error {
func (d Dead) Check(options CheckOptions) error {
if options.Parallelism < 1 {
options.Parallelism = runtime.NumCPU()
}
Expand All @@ -110,24 +111,24 @@ func (d Dead) Check(path string, options CheckOptions) error {

// Range over the results channel which should return the URL, status code and the message
// if it's not ok. But not stop the loop, we need to keep processing all links
logger := d.logger.With(slog.String("path", path))
logger := d.logger.With(slog.String("path", options.Path))
logger.Debug("Checking links")

info, err := os.Stat(path)
info, err := os.Stat(options.Path)
if err != nil {
return fmt.Errorf("os.Stat(%s): %w", path, err)
return fmt.Errorf("os.Stat(%s): %w", options.Path, err)
}

if info.Mode().IsDir() {
return errors.New("TODO: Support recursing a directory searching for links")
}

if !info.Mode().IsRegular() {
return fmt.Errorf("%s has unsupported file mode: %s", path, info.Mode())
return fmt.Errorf("%s has unsupported file mode: %s", options.Path, info.Mode())
}

// Now we know it's a regular file
f, err := os.Open(path)
f, err := os.Open(options.Path)
if err != nil {
return err
}
Expand All @@ -139,7 +140,7 @@ func (d Dead) Check(path string, options CheckOptions) error {

links := extractLinks(ctx, f)

spinner := spin.New(d.stdout, "Checking "+path)
spinner := spin.New(d.stdout, "Checking "+options.Path)

spinner.Start()
workers := make([]<-chan CheckResult, 0, options.Parallelism)
Expand Down
3 changes: 2 additions & 1 deletion internal/dead/dead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ func TestMain(m *testing.M) {
"check": func() {
app := dead.New(os.Stdout, os.Stderr, false, "test")
options := dead.CheckOptions{
Path: os.Args[1],
Debug: false,
RequestTimeout: dead.DefaultRequestTimeout,
Timeout: dead.DefaultOverallTimeout,
}
if err := app.Check(os.Args[1], options); err != nil {
if err := app.Check(options); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1) //nolint:revive // redundant-test-main-exit, this is a testscript main
}
Expand Down
Loading