@@ -595,7 +595,7 @@ public final class XcodeInstaller {
595
595
}
596
596
}
597
597
598
- public func uninstallXcode( _ versionString: String , directory: Path ) -> Promise < Void > {
598
+ public func uninstallXcode( _ versionString: String , directory: Path , deleteApp : Bool ) -> Promise < Void > {
599
599
return firstly { ( ) -> Promise < InstalledXcode > in
600
600
guard let version = Version ( xcodeVersion: versionString) else {
601
601
Current . logging. log ( Error . invalidVersion ( versionString) . legibleLocalizedDescription)
@@ -609,11 +609,17 @@ public final class XcodeInstaller {
609
609
610
610
return Promise . value ( installedXcode)
611
611
}
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
614
620
// If we just uninstalled the selected Xcode, try to select the latest installed version so things don't accidentally break
615
621
Current . shell. xcodeSelectPrintPath ( )
616
- . then { output -> Promise < ( InstalledXcode , URL ) > in
622
+ . then { output -> Promise < ( InstalledXcode , URL ? ) > in
617
623
if output. out. hasPrefix ( installedXcode. path. string) ,
618
624
let latestInstalledXcode = Current . files. installedXcodes ( directory) . sorted ( by: { $0. version < $1. version } ) . last {
619
625
return selectXcodeAtPath ( latestInstalledXcode. path. string)
@@ -628,7 +634,12 @@ public final class XcodeInstaller {
628
634
}
629
635
}
630
636
. 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
+ }
632
643
Current . shell. exit ( 0 )
633
644
}
634
645
}
0 commit comments