Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Say in peel projects --json why a folder isn't suggested and what wasn't searched
Țugui Dragoș9c5cf961b236
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swiftindex 2928eeb7..d7e6379d 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift@@ -543,6 +543,8 @@ struct ProjectsCommand: AsyncParsableCommand {let recentlyActive: Bool/// Why measuring the folder left it to be chosen by hand, or `null` when nothing did.let heldBack: String?+ /// Why the folder isn't suggested, in the words of the list's last column, or `null` when it is.+ let reason: String?private enum CodingKeys: String, CodingKey {case path@@ -552,9 +554,10 @@ struct ProjectsCommand: AsyncParsableCommand {case suggestedcase recentlyActivecase heldBack+ case reason}- /// Encodes a missing `heldBack` as `null`, for the reason `AppRecord` gives.+ /// Encodes a missing `heldBack` or `reason` as `null`, for the reason `AppRecord` gives.func encode(to encoder: any Encoder) throws {var container = encoder.container(keyedBy: CodingKeys.self)try container.encode(path, forKey: .path)@@ -564,6 +567,7 @@ struct ProjectsCommand: AsyncParsableCommand {try container.encode(suggested, forKey: .suggested)try container.encode(recentlyActive, forKey: .recentlyActive)try container.encode(heldBack, forKey: .heldBack)+ try container.encode(reason, forKey: .reason)}}@@ -603,6 +607,10 @@ struct ProjectsCommand: AsyncParsableCommand {struct Report: Encodable {let artifacts: [Record]let unreadableLocations: [String]+ /// Chosen folders the scan didn't search.+ let skippedLocations: [String]+ /// True when there were more folders than Peel looks at in one go, so the list isn't all of them.+ let cutShort: Bool}/// What the scan couldn't look at, said on standard error whatever the output, so that an empty answer is not@@ -630,10 +638,13 @@ struct ProjectsCommand: AsyncParsableCommand {size: MeasuredSize($0.size),suggested: $0.isRecommended,recentlyActive: $0.isRecentlyActive,- heldBack: $0.heldBack?.rawValue+ heldBack: $0.heldBack?.rawValue,+ reason: reason(for: $0))},- unreadableLocations: scan.unreadableLocations.map(Output.path)+ unreadableLocations: scan.unreadableLocations.map(Output.path),+ skippedLocations: scan.refusedRoots.map { Output.path($0.url) },+ cutShort: scan.wasCutShort)}@@ -684,13 +695,18 @@ struct ProjectsCommand: AsyncParsableCommand {/// Says in words why `artifact` is kept, or "suggested".static func note(for artifact: ProjectArtifact) -> String {+ reason(for: artifact).map { "\($0), kept" } ?? "suggested"+ }++ /// Why `artifact` isn't suggested, or nil when it is.+ static func reason(for artifact: ProjectArtifact) -> String? {switch artifact.keptBecause {- case .heldBack(let heldBack): "\(heldBack.summary), kept"- case .installedPackages: "installed packages, kept"- case .genericName: "name could mean anything, kept"- case .changedRecently: "changed in the last 7 days, kept"- case .lastChangeNotKnown: "too large to tell when it last changed, kept"- case nil: "suggested"+ case .heldBack(let heldBack): heldBack.summary+ case .installedPackages: "installed packages"+ case .genericName: "name could mean anything"+ case .changedRecently: "changed in the last 7 days"+ case .lastChangeNotKnown: "too large to tell when it last changed"+ case nil: nil}}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swiftindex 5a3ffa4a..ed12fe85 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift@@ -428,7 +428,7 @@ struct FileCommandTests {/// The note is the other half of `isRecommended`: a folder that is kept must say why, and one that is/// suggested must not claim to be kept.- @Test func everyKeptFolderSaysWhyAndEverySuggestedOneDoesNot() {+ @Test func everyKeptFolderSaysWhyAndEverySuggestedOneDoesNot() throws {let project = URL(filePath: "/Users/me/Developer/App", directoryHint: .isDirectory)func artifact(_ name: String,@@ -471,6 +471,13 @@ struct FileCommandTests {}#expect(ProjectsCommand.rows(for: cases.map(\.0)).map(\.count) == cases.map { _ in 4 })#expect(ProjectsCommand.rows(for: cases.map(\.0))[0] == ["20 bytes", "/Users/me/Developer/App/DerivedData", "Xcode", "suggested"])+ let json = try Output.jsonText(ProjectsCommand.report(for: ProjectArtifacts.Scan(artifacts: cases.map(\.0))))+ let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])+ let records = try #require(report["artifacts"] as? [[String: Any]])+ #expect(records.map { $0["reason"] as? String ?? "suggested" } == cases.map {+ $0.1 == "suggested" ? "suggested" : String($0.1.dropLast(", kept".count))+ })+ #expect(records[0]["reason"] is NSNull)}/// The first copy is the one Peel suggests keeping, and it is the only row marked.@@ -746,13 +753,18 @@ struct FileCommandTests {let json = try Output.jsonText(ProjectsCommand.report(for: scan))let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])#expect(report["unreadableLocations"] as? [String] == ["/Users/me/Library/Safari"])+ #expect(report["cutShort"] as? Bool == true)}- @Test func namesEachChosenFolderTheScanDidNotSearch() {+ @Test func namesEachChosenFolderTheScanDidNotSearch() throws {let unplugged = URL(filePath: "/Volumes/Disk/Projects", directoryHint: .isDirectory)let scan = ProjectArtifacts.Scan(refusedRoots: [(unplugged, .notAFolder)])#expect(ProjectsCommand.notes(for: scan) == ["/Volumes/Disk/Projects: it isn't a folder Peel can reach"])+ let json = try Output.jsonText(ProjectsCommand.report(for: scan))+ let report = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any])+ #expect(report["skippedLocations"] as? [String] == ["/Volumes/Disk/Projects"])+ #expect(report["cutShort"] as? Bool == false)}/// `peel caches --json` says which folders `--remove` would take.