Skip to content

Free, open-source macOS cleaner. CleanMyMac alternative with zero telemetry. Native SwiftUI, scheduled auto-cleaning, Xcode/Homebrew/system cache cleanup. MIT licensed.

fix(cli): only enter CLI mode for known commands (#68)

Dávid Balatoni03372c18d2e0
diff --git a/PureMac/Logic/Utilities/CLI.swift b/PureMac/Logic/Utilities/CLI.swift
index 96b4815..640acea 100644
--- a/PureMac/Logic/Utilities/CLI.swift
+++ b/PureMac/Logic/Utilities/CLI.swift
@@ -1,6 +1,16 @@
import Foundation
struct CLI {
+ private static let knownCommands: Set<String> = [
+ "scan", "disk-info", "list",
+ "help", "--help", "-h",
+ "version", "--version", "-v",
+ ]
+
+ static func isKnownCommand(_ arg: String) -> Bool {
+ knownCommands.contains(arg)
+ }
+
static func run() -> Never {
let args = Array(CommandLine.arguments.dropFirst())
diff --git a/PureMac/PureMacApp.swift b/PureMac/PureMacApp.swift
index 68fd00e..fde9bff 100644
--- a/PureMac/PureMacApp.swift
+++ b/PureMac/PureMacApp.swift
@@ -16,7 +16,11 @@ struct PureMacApp: App {
@AppStorage("PureMac.OnboardingComplete") private var onboardingComplete = false
init() {
- if CommandLine.arguments.count > 1 {
+ // Enter CLI mode only when the first arg is a known command. Xcode and
+ // LaunchServices inject args like -NSDocumentRevisionsDebugMode and
+ // -psn_<pid> that must not be interpreted as CLI commands.
+ if let first = CommandLine.arguments.dropFirst().first,
+ CLI.isKnownCommand(first) {
CLI.run()
}
}