Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

peel inventory is quiet about Homebrew on a Mac without it

Țugui Dragoșd08061a99685
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 6930da88..7cff54cc 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -53,10 +53,18 @@ struct InventoryCommand: AsyncParsableCommand {
guard chosen != .brewfile else {
throw CommandFailure("Homebrew didn't answer, so there is nothing to write a Brewfile from.\n\(why)")
}
- Output.note("Homebrew didn't answer, so no app is marked as installed by it.")
+ if let note = Self.homebrewNote(isInstalled: Homebrew.executableURL != nil, why: why) {
+ Output.note(note)
+ }
return []
}
+ /// What a list other than a Brewfile says when Homebrew gave no packages: nothing on a Mac without Homebrew,
+ /// and why otherwise.
+ static func homebrewNote(isInstalled: Bool, why: String) -> String? {
+ isInstalled ? "Homebrew didn't answer, so no app is marked as installed by it.\n\(why)" : nil
+ }
+
/// Why Homebrew was not asked: without its local copy of the definitions it would download them. The copy is
/// missing because Homebrew isn't installed, or because it never fetched one.
static func noDefinitions(isInstalled: Bool) -> String {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index f9cd3611..adcf628b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -13,6 +13,16 @@ struct CommandLineTests {
#expect(InventoryCommand.noDefinitions(isInstalled: true) == "Homebrew has no list of packages on this Mac. Run `brew update` first.")
}
+ /// A list of apps says nothing of Homebrew on a Mac without it, and says why when Homebrew is there and did
+ /// not answer.
+ @Test func speaksOfHomebrewOnlyWhereItIsInstalled() {
+ #expect(InventoryCommand.homebrewNote(isInstalled: false, why: "Homebrew isn't installed.") == nil)
+ #expect(
+ InventoryCommand.homebrewNote(isInstalled: true, why: "Error: no network")
+ == "Homebrew didn't answer, so no app is marked as installed by it.\nError: no network"
+ )
+ }
+
@Test func parsesByteSizes() {
#expect(ByteSize(argument: "2048")?.bytes == 2_048)
#expect(ByteSize(argument: "500KB")?.bytes == 500_000)