Skip to content

Commit 49d5e82

Browse files
committed
Added --delete-app flag to xcodes uninstall
This is equivalent to the `--delete-xip` flag that was added to `xcodes install` on the previous commit.
1 parent 1c7de08 commit 49d5e82

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ public final class XcodeInstaller {
595595
}
596596
}
597597

598-
public func uninstallXcode(_ versionString: String, directory: Path) -> Promise<Void> {
598+
public func uninstallXcode(_ versionString: String, directory: Path, deleteApp: Bool) -> Promise<Void> {
599599
return firstly { () -> Promise<InstalledXcode> in
600600
guard let version = Version(xcodeVersion: versionString) else {
601601
Current.logging.log(Error.invalidVersion(versionString).legibleLocalizedDescription)
@@ -609,11 +609,17 @@ public final class XcodeInstaller {
609609

610610
return Promise.value(installedXcode)
611611
}
612-
.map { ($0, try Current.files.trashItem(at: $0.path.url)) }
613-
.then { (installedXcode, trashURL) -> Promise<(InstalledXcode, URL)> in
612+
.map { installedXcode -> (InstalledXcode, URL?) in
613+
if deleteApp {
614+
try Current.files.removeItem(at: installedXcode.path.url)
615+
return (installedXcode, nil)
616+
}
617+
return (installedXcode, try Current.files.trashItem(at: installedXcode.path.url))
618+
}
619+
.then { (installedXcode, trashURL) -> Promise<(InstalledXcode, URL?)> in
614620
// If we just uninstalled the selected Xcode, try to select the latest installed version so things don't accidentally break
615621
Current.shell.xcodeSelectPrintPath()
616-
.then { output -> Promise<(InstalledXcode, URL)> in
622+
.then { output -> Promise<(InstalledXcode, URL?)> in
617623
if output.out.hasPrefix(installedXcode.path.string),
618624
let latestInstalledXcode = Current.files.installedXcodes(directory).sorted(by: { $0.version < $1.version }).last {
619625
return selectXcodeAtPath(latestInstalledXcode.path.string)
@@ -628,7 +634,12 @@ public final class XcodeInstaller {
628634
}
629635
}
630636
.done { (installedXcode, trashURL) in
631-
Current.logging.log("Xcode \(installedXcode.version.appleDescription) moved to Trash: \(trashURL.path)".green)
637+
if let trashURL = trashURL {
638+
Current.logging.log("Xcode \(installedXcode.version.appleDescription) moved to Trash: \(trashURL.path)".green)
639+
}
640+
else {
641+
Current.logging.log("Xcode \(installedXcode.version.appleDescription) deleted".green)
642+
}
632643
Current.shell.exit(0)
633644
}
634645
}

Sources/xcodes/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ struct Xcodes: ParsableCommand {
351351
completion: .custom { _ in Current.files.installedXcodes(getDirectory(possibleDirectory: nil)).sorted { $0.version < $1.version }.map { $0.version.appleDescription } })
352352
var version: [String] = []
353353

354+
@Flag(help: "Completely delete Xcode, instead of moving it to the user's Trash.")
355+
var deleteApp: Bool = false
356+
354357
@OptionGroup
355358
var globalDirectory: GlobalDirectoryOption
356359

@@ -362,7 +365,7 @@ struct Xcodes: ParsableCommand {
362365

363366
let directory = getDirectory(possibleDirectory: globalDirectory.directory)
364367

365-
installer.uninstallXcode(version.joined(separator: " "), directory: directory)
368+
installer.uninstallXcode(version.joined(separator: " "), directory: directory, deleteApp: deleteApp)
366369
.done { Uninstall.exit() }
367370
.catch { error in Uninstall.exit(withLegibleError: error) }
368371

Tests/XcodesKitTests/XcodesKitTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ final class XcodesKitTests: XCTestCase {
778778
return Promise.value((status: 0, out: "", err: ""))
779779
}
780780

781-
installer.uninstallXcode("0.0.0", directory: Path.root.join("Applications"))
781+
installer.uninstallXcode("0.0.0", directory: Path.root.join("Applications"), deleteApp: false)
782782
.ensure {
783783
XCTAssertEqual(selectedPaths, ["/Applications/Xcode-2.0.1.app"])
784784
XCTAssertEqual(trashedItemAtURL, installedXcodes[0].path.url)
@@ -823,7 +823,7 @@ final class XcodesKitTests: XCTestCase {
823823
return URL(fileURLWithPath: "\(NSHomeDirectory())/.Trash/\(itemURL.lastPathComponent)")
824824
}
825825

826-
installer.uninstallXcode("999", directory: Path.root.join("Applications"))
826+
installer.uninstallXcode("999", directory: Path.root.join("Applications"), deleteApp: false)
827827
.ensure {
828828
XCTAssertEqual(trashedItemAtURL, installedXcodes[0].path.url)
829829
}

0 commit comments

Comments
 (0)