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 orphans says what its --remove moves

Țugui Dragoș4c4873c6dfe2
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 4fa660fa..d30a12de 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -12,6 +12,9 @@ struct OrphansCommand: AsyncParsableCommand {
@Argument(help: "The group to move, as `peel orphans` names it in its first column.")
var group: String?
+ @Flag(help: "Move the named group to the Trash, leaving out what Peel holds back.")
+ var remove = false
+
@OptionGroup var removal: RemovalOptions
@OptionGroup var output: OutputOptions
@@ -52,9 +55,9 @@ struct OrphansCommand: AsyncParsableCommand {
}
func validate() throws {
- try removal.validate(with: output)
- guard removal.remove == (group != nil) else {
- throw ValidationError(removal.remove
+ try removal.validate(removing: remove, with: output)
+ guard remove == (group != nil) else {
+ throw ValidationError(remove
? "Name the group to move. See `peel orphans`."
: "A group on its own does nothing. Add --remove to move it.")
}
@@ -174,6 +177,9 @@ struct CachesCommand: AsyncParsableCommand {
@Argument(help: "Tools to look at, as `peel caches` names them. All of them when none is given.")
var tools: [String] = []
+ @Flag(help: RemovalOptions.movesWhatPeelSuggests)
+ var remove = false
+
@OptionGroup var removal: RemovalOptions
@OptionGroup var output: OutputOptions
@@ -194,13 +200,13 @@ struct CachesCommand: AsyncParsableCommand {
}
func validate() throws {
- try removal.validate(with: output)
+ try removal.validate(removing: remove, with: output)
}
func run() async throws {
let all = await DeveloperCaches.scan(exclusions: UnreadableExclusions.load())
let environments = try Self.chosen(from: all, named: tools)
- guard !removal.remove else {
+ guard !remove else {
return try await clean(environments, using: TrashService(exclusions: await ExclusionStore().load()))
}
@@ -305,6 +311,9 @@ struct ProjectsCommand: AsyncParsableCommand {
@Argument(help: "Folders your projects live in.", completion: .directory)
var folders: [String]
+ @Flag(help: RemovalOptions.movesWhatPeelSuggests)
+ var remove = false
+
@OptionGroup var removal: RemovalOptions
@OptionGroup var output: OutputOptions
@@ -345,7 +354,7 @@ struct ProjectsCommand: AsyncParsableCommand {
/// Fails when none of the folders can be searched, giving the reason for each, rather than report that
/// nothing built was found.
func validate() throws {
- try removal.validate(with: output)
+ try removal.validate(removing: remove, with: output)
let refused = folders.map(URL.init(argument:)).compactMap { root in
ProjectArtifacts.refusal(for: root).map { "\(Output.plain(Output.path(root))): \($0.summary)" }
}
@@ -364,7 +373,7 @@ struct ProjectsCommand: AsyncParsableCommand {
}
let scan = await ProjectArtifacts.scan(roots: roots, exclusions: UnreadableExclusions.load())
let artifacts = scan.artifacts
- if removal.remove {
+ if remove {
Self.notes(for: scan).forEach(Output.note)
return try await clean(artifacts, using: TrashService(exclusions: await ExclusionStore().load()))
}
@@ -476,6 +485,9 @@ struct DuplicatesCommand: AsyncParsableCommand {
@Option(name: .customLong("min-size"), help: "Only files at least this large, and folders holding at least this much, like 500KB or 1.5GB.")
var minimumSize: ByteSize?
+ @Flag(help: RemovalOptions.movesWhatPeelSuggests)
+ var remove = false
+
@OptionGroup var removal: RemovalOptions
@OptionGroup var output: OutputOptions
@@ -504,7 +516,7 @@ struct DuplicatesCommand: AsyncParsableCommand {
/// Checks the folders here rather than in `run()`: only while it parses does ArgumentParser know which
/// subcommand's usage to print. The finder needs no exclusions, since they don't decide what can be scanned.
func validate() throws {
- try removal.validate(with: output)
+ try removal.validate(removing: remove, with: output)
// One finder for every folder: each new finder resolves the home folder's links again.
let finder = DuplicateFinder()
let urls = folders.map(URL.init(argument:))
@@ -525,7 +537,7 @@ struct DuplicatesCommand: AsyncParsableCommand {
options.kind = kind?.fileKind ?? .any
options.minimumSize = minimumSize?.bytes ?? 1
let scan = try await finder.scan(options)
- if removal.remove {
+ if remove {
Self.notes(for: scan).forEach(Output.note)
return try await clean(scan, using: TrashService(exclusions: await ExclusionStore().load()))
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift
index ff1386c9..13962a98 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift
@@ -2,9 +2,10 @@ import ArgumentParser
import Foundation
import PeelCore
+/// What goes with a command's own `--remove`, which each command declares with the help that says what it moves.
struct RemovalOptions: ParsableArguments {
- @Flag(help: "Move what Peel suggests to the Trash.")
- var remove = false
+ /// The help of `--remove` for a command that moves what Peel suggests.
+ static let movesWhatPeelSuggests: ArgumentHelp = "Move what Peel suggests to the Trash."
@Flag(name: .customLong("dry-run"), help: "Show what would go without moving anything.")
var dryRun = false
@@ -12,7 +13,7 @@ struct RemovalOptions: ParsableArguments {
@Flag(name: .shortAndLong, help: "Don't ask for confirmation.")
var yes = false
- func validate(with output: OutputOptions) throws {
+ func validate(removing remove: Bool, with output: OutputOptions) throws {
guard remove || (!dryRun && !yes) else {
throw ValidationError("--dry-run and --yes only go with --remove.")
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 3560f660..0a868f7c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -705,6 +705,16 @@ struct CommandLineTests {
#expect(row(.possible) == "bundle identifier, review: possible match")
}
+ /// Nothing in Orphaned Files is ever suggested, so its `--remove` says what it moves instead: the group named.
+ @Test func removeSaysWhatEachCommandMoves() {
+ let orphans = OrphansCommand.helpMessage(columns: 200)
+ #expect(orphans.contains("Move the named group to the Trash, leaving out what Peel holds back."))
+ #expect(!orphans.contains("Move what Peel suggests"))
+ for help in [CachesCommand.helpMessage(columns: 200), ProjectsCommand.helpMessage(columns: 200), DuplicatesCommand.helpMessage(columns: 200)] {
+ #expect(help.contains("Move what Peel suggests to the Trash."))
+ }
+ }
+
@Test func showsTheUsageOfTheSubcommandThatFailed() throws {
let error = #expect(throws: (any Error).self) { try PeelCommand.parseAsRoot(["inventory", "--format", "bogus"]) }
let message = PeelCommand.fullMessage(for: try #require(error), columns: 200)
@@ -782,7 +792,7 @@ struct CommandLineTests {
/// A flag that only makes sense with `--remove` is refused without it, rather than quietly ignored.
/// `--json` only lists, so it is refused with `--remove`.
@Test func removalFlagsOnlyGoWithARemoval() throws {
- #expect(try (PeelCommand.parseAsRoot(["caches", "--remove", "--dry-run"]) as? CachesCommand)?.removal.remove == true)
+ #expect(try (PeelCommand.parseAsRoot(["caches", "--remove", "--dry-run"]) as? CachesCommand)?.remove == true)
for arguments in [["caches", "--dry-run"], ["caches", "-y"], ["projects", "~/x", "--dry-run"], ["duplicates", "--yes"]] {
#expect(throws: (any Error).self) { try PeelCommand.parseAsRoot(arguments) }
}
diff --git a/Support/peel.1 b/Support/peel.1
index 9871e32c..f22d90eb 100644
--- a/Support/peel.1
+++ b/Support/peel.1
@@ -97,7 +97,7 @@ Nothing here is ever suggested, so --remove takes the identifier of one group. W
.It Ar group
The group to move, as `peel orphans` names it in its first column.
.It Fl -remove
-Move what Peel suggests to the Trash.
+Move the named group to the Trash, leaving out what Peel holds back.
.It Fl -dry-run
Show what would go without moving anything.
.It Fl y , -yes