From 63c08cf99aefaa34b1b0c80ebadea76f88ce82ab Mon Sep 17 00:00:00 2001 From: Anas Lakhani Date: Sun, 25 Oct 2026 08:38:40 +0500 Subject: [PATCH 1/2] Fail on an unknown background action instead of listing items `removemacai background of` (a typo for off) printed the list and exited 0. Anything other than off, on or nothing now fails naming the action, before scanning the items. Fixes #82 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + Sources/removemacai/SelfTest.swift | 5 +++++ Sources/removemacai/TweakCommands.swift | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f00db8c..a410016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `removemacai background` with an action other than `off` or `on`, such as the typo `of`, now fails and says which actions it takes, instead of listing the items and exiting 0 (#82). - Block Music launches is now called Stop Music from opening, even by hand, and its warning says Music won't open at all until you undo it. The old name read as if only AirPods were blocked (#67). ## 1.2.0-beta.1 diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index 3d3073d..f5f09de 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -42,6 +42,11 @@ func selfTest() -> Bool { check(unknownCommand.status == 1 && unknownCommandOutput.contains("error: unknown command \"stauts\"") && unknownCommandOutput.contains("Did you mean \"status\"?"), "an unknown command fails naming the typo instead of printing bare usage") + let unknownAction = Shell.run(executable, ["background", "of"]) + let unknownActionOutput = unknownAction.output.replacingOccurrences( + of: #"\x1B\[[0-9;]*m"#, with: "", options: .regularExpression) + check(unknownAction.status == 1 && unknownActionOutput.contains("error: unknown action \"of\", use off or on"), + "background fails on an unknown action instead of listing items") check(Set(Catalog.setsToRemove(keeping: [])) == Set(Catalog.availableModelSets.map(\.name)), "off removes every model set this macOS has") diff --git a/Sources/removemacai/TweakCommands.swift b/Sources/removemacai/TweakCommands.swift index ca592bf..d87e674 100644 --- a/Sources/removemacai/TweakCommands.swift +++ b/Sources/removemacai/TweakCommands.swift @@ -136,9 +136,12 @@ enum TweakCommands { // MARK: background items static func background(_ args: [String], yes: Bool) -> Bool { + if let action = args.first, action != "off" && action != "on" { + Term.fail("unknown action \"\(action)\", use off or on") + } let items = BackgroundItems.scan() let labels = BackgroundItems.disabledLabels() - guard let action = args.first, action == "off" || action == "on" else { + guard let action = args.first else { Commands.header() if items.isEmpty { print("No background items from other apps.") From 27862ae12ec83682e1bb76423e77e75a5d793a3b Mon Sep 17 00:00:00 2001 From: Anas Lakhani Date: Sun, 25 Oct 2026 09:13:32 +0500 Subject: [PATCH 2/2] Require the unknown background action to print only the error The check passed as long as the error text was somewhere in the output, so listing the items first would still have passed it. Co-Authored-By: Claude Opus 5.5 --- Sources/removemacai/SelfTest.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/removemacai/SelfTest.swift b/Sources/removemacai/SelfTest.swift index f5f09de..36712fc 100644 --- a/Sources/removemacai/SelfTest.swift +++ b/Sources/removemacai/SelfTest.swift @@ -45,7 +45,8 @@ func selfTest() -> Bool { let unknownAction = Shell.run(executable, ["background", "of"]) let unknownActionOutput = unknownAction.output.replacingOccurrences( of: #"\x1B\[[0-9;]*m"#, with: "", options: .regularExpression) - check(unknownAction.status == 1 && unknownActionOutput.contains("error: unknown action \"of\", use off or on"), + check(unknownAction.status == 1 + && unknownActionOutput.trimmingCharacters(in: .whitespacesAndNewlines) == "error: unknown action \"of\", use off or on", "background fails on an unknown action instead of listing items") check(Set(Catalog.setsToRemove(keeping: [])) == Set(Catalog.availableModelSets.map(\.name)),