From ebf7546e682c582ca7bf8aaed7b4b156815ff822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeffry=20W=C3=BCrmli?= Date: Thu, 12 Nov 2026 13:28:24 +0100 Subject: [PATCH] fix: reject --force without --kill --- README.md | 2 +- internal/cli/run.go | 3 +++ internal/cli/run_test.go | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c99a6f..a49fb33 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ With `--kill`, every port gets a status line (`✓` stopped, `ℹ` left untouche | :-: | --- | --- | | 🛑 | `-k`, `--kill` | stop the cause of a busy port after confirmation | | ✅ | `-y`, `--yes` | skip the confirmation prompt (requires `--kill`) | -| 💥 | `--force` | send SIGKILL immediately instead of SIGTERM (only has an effect together with `--kill`) | +| 💥 | `--force` | send SIGKILL immediately instead of SIGTERM (requires `--kill`) | | 👀 | `--dry-run` | show what `--kill` would do without doing it | | 🔎 | `--source ` | only show ports held by this source: `docker`, `systemd`, `launchd` or `process` (repeatable, comma-separated) | | 🤖 | `--json` | print machine-readable JSON (`"version": 1`) | diff --git a/internal/cli/run.go b/internal/cli/run.go index 0403d5b..bece393 100644 --- a/internal/cli/run.go +++ b/internal/cli/run.go @@ -48,6 +48,9 @@ func Run(ctx context.Context, d Deps, args []string, flags Flags) int { if flags.Yes && !flags.Kill { return fail(d, errors.New("--yes requires --kill")) } + if flags.Force && !flags.Kill { + return fail(d, errors.New("--force requires --kill")) + } svc := report.Service{Sockets: d.Sockets, Procs: d.Procs, Detector: d.Detector} reports, err := svc.Explain(ctx, ports) diff --git a/internal/cli/run_test.go b/internal/cli/run_test.go index 88d710b..1232af1 100644 --- a/internal/cli/run_test.go +++ b/internal/cli/run_test.go @@ -238,6 +238,19 @@ func TestRun_YesWithoutKillExit2(t *testing.T) { } } +func TestRun_ForceWithoutKillExit2(t *testing.T) { + d, _, stderr := testDeps(fakeSockets{sockets: []socket.Socket{listener(3000, 42)}}) + + got := Run(context.Background(), d, []string{"3000"}, Flags{Force: true}) + + if got != 2 { + t.Errorf("exit = %d, want 2", got) + } + if !strings.Contains(stderr.String(), "--force requires --kill") { + t.Errorf("stderr = %q, want it to contain %q", stderr.String(), "--force requires --kill") + } +} + func TestRun_NoColorWhenNotTTY(t *testing.T) { d, stdout, _ := testDeps(fakeSockets{sockets: []socket.Socket{listener(3000, 42)}})