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
9 changes: 8 additions & 1 deletion cmd/dead/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"context"
"os"
"os/signal"

"go.followtheprocess.codes/dead/internal/cmd"
"go.followtheprocess.codes/msg"
Expand All @@ -15,10 +17,15 @@ func main() {
}

func run() error {
ctx := context.Background()

ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
defer cancel()

cli, err := cmd.Build()
if err != nil {
return err
}

return cli.Execute()
return cli.Execute(ctx)
}
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.17.0
go.followtheprocess.codes/cli v0.18.0
go.followtheprocess.codes/hue v1.0.0
go.followtheprocess.codes/log v1.2.0
go.followtheprocess.codes/msg v1.9.2
Expand All @@ -14,6 +14,6 @@ require (

require (
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/term v0.37.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.17.0 h1:wAahiHmRUGEZ72jXOrZw5mPzU5h5qYDzqEt39zaW684=
go.followtheprocess.codes/cli v0.17.0/go.mod h1:vNqup3nFyWFAqJdZyL8s29ES/dt2FOJsvJ7kFH+CgWc=
go.followtheprocess.codes/cli v0.18.0 h1:lOf/ENPGmkIy+gaSQjde2/KF76rVWSZs6OWh0b9a+2E=
go.followtheprocess.codes/cli v0.18.0/go.mod h1:ne10OqfFoZgMX2Q6XDrd25qHKqD2iPVQqQubniRdfBk=
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 @@ -16,7 +16,7 @@ go.followtheprocess.codes/test v1.0.0 h1:5m2MPOQpohDC9pf5hgqpH+4ldJP5g+YFVdoGQY4
go.followtheprocess.codes/test v1.0.0/go.mod h1:e627pR8IhsTV/RfuP/WKYjyL0BmuIbmaw2iKlQBCWrY=
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/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
19 changes: 13 additions & 6 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package cmd

import (
"context"
"runtime"

"go.followtheprocess.codes/cli"
Expand Down Expand Up @@ -34,25 +35,31 @@ func check() (*cli.Command, error) {
"check",
cli.Short("Check a file or files in a directory (recursively) for dead links"),
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.Debug, "debug", flag.NoShortHand, "Enable debug logging"),
cli.Flag(
&options.Timeout,
"timeout",
't',
"Timeout for the entire operation",
cli.FlagDefault(dead.DefaultOverallTimeout),
),
cli.Flag(
&options.RequestTimeout,
"request-timeout",
'r',
dead.DefaultRequestTimeout,
"Timeout for each request",
cli.FlagDefault(dead.DefaultRequestTimeout),
),
cli.Flag(
&options.Parallelism,
"parallelism",
'p',
runtime.NumCPU(),
"Number of goroutines available for checking",
cli.FlagDefault(runtime.NumCPU()),
),
cli.Run(func(cmd *cli.Command) error {
cli.Run(func(ctx context.Context, cmd *cli.Command) error {
dead := dead.New(cmd.Stdout(), cmd.Stderr(), options.Debug, version)
return dead.Check(options)
return dead.Check(ctx, options)
}),
)
}
4 changes: 2 additions & 2 deletions internal/dead/dead.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ type CheckResult struct {
}

// Check is the entry point for the `dead check` subcommand.
func (d Dead) Check(options CheckOptions) error {
func (d Dead) Check(ctx context.Context, options CheckOptions) error {
if options.Parallelism < 1 {
options.Parallelism = runtime.NumCPU()
}
start := time.Now()

ctx, cancel := context.WithTimeout(context.Background(), options.Timeout)
ctx, cancel := context.WithTimeout(ctx, options.Timeout)
defer cancel()

// See if path is a file or a directory
Expand Down
3 changes: 2 additions & 1 deletion internal/dead/dead_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dead_test

import (
"context"
"flag"
"fmt"
"net/http"
Expand All @@ -25,7 +26,7 @@ func TestMain(m *testing.M) {
RequestTimeout: dead.DefaultRequestTimeout,
Timeout: dead.DefaultOverallTimeout,
}
if err := app.Check(options); err != nil {
if err := app.Check(context.Background(), 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