Skip to content

Commit c49767b

Browse files
committed
Renamed --delete-xip and --delete-app flags to --empty-trash
This two flags do essentially the same thing (skip the Trash and irrevocably delete Xcode or its .xip) so it makes sense to use the same name for both. - Although the Trash isn't really "emptied" (the files never get to the Trash in the first place), this is the most intuitively way I've found to refer to this at a high level. - Alternatives considered: - `--skip-trash`. This explains better the current implementation, but I think it's more ambiguous: if the user doesn't know that by default files are moved to the Trash, "skip Trash" could be understood as "skip deleting files from the Trash"... - `--delete-immediately` (the way Finder refers to deleting a single file from the Trash). This is longer to type, and "immediately" could imply that, without this flag, files will be automatically deleted in the future somehow.
1 parent 49d5e82 commit c49767b

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,22 @@ public final class XcodeInstaller {
166166
case aria2(Path)
167167
}
168168

169-
public func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, experimentalUnxip: Bool = false, deleteXip: Bool, noSuperuser: Bool) -> Promise<Void> {
169+
public func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, experimentalUnxip: Bool = false, emptyTrash: Bool, noSuperuser: Bool) -> Promise<Void> {
170170
return firstly { () -> Promise<InstalledXcode> in
171-
return self.install(installationType, dataSource: dataSource, downloader: downloader, destination: destination, attemptNumber: 0, experimentalUnxip: experimentalUnxip, deleteXip: deleteXip, noSuperuser: noSuperuser)
171+
return self.install(installationType, dataSource: dataSource, downloader: downloader, destination: destination, attemptNumber: 0, experimentalUnxip: experimentalUnxip, emptyTrash: emptyTrash, noSuperuser: noSuperuser)
172172
}
173173
.done { xcode in
174174
Current.logging.log("\nXcode \(xcode.version.descriptionWithoutBuildMetadata) has been installed to \(xcode.path.string)".green)
175175
Current.shell.exit(0)
176176
}
177177
}
178178

179-
private func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, attemptNumber: Int, experimentalUnxip: Bool, deleteXip: Bool, noSuperuser: Bool) -> Promise<InstalledXcode> {
179+
private func install(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path, attemptNumber: Int, experimentalUnxip: Bool, emptyTrash: Bool, noSuperuser: Bool) -> Promise<InstalledXcode> {
180180
return firstly { () -> Promise<(Xcode, URL)> in
181181
return self.getXcodeArchive(installationType, dataSource: dataSource, downloader: downloader, destination: destination, willInstall: true)
182182
}
183183
.then { xcode, url -> Promise<InstalledXcode> in
184-
return self.installArchivedXcode(xcode, at: url, to: destination, experimentalUnxip: experimentalUnxip, deleteXip: deleteXip, noSuperuser: noSuperuser)
184+
return self.installArchivedXcode(xcode, at: url, to: destination, experimentalUnxip: experimentalUnxip, emptyTrash: emptyTrash, noSuperuser: noSuperuser)
185185
}
186186
.recover { error -> Promise<InstalledXcode> in
187187
switch error {
@@ -198,7 +198,7 @@ public final class XcodeInstaller {
198198
Current.logging.log(error.legibleLocalizedDescription.red)
199199
Current.logging.log("Removing damaged XIP and re-attempting installation.\n")
200200
try Current.files.removeItem(at: damagedXIPURL)
201-
return self.install(installationType, dataSource: dataSource, downloader: downloader, destination: destination, attemptNumber: attemptNumber + 1, experimentalUnxip: experimentalUnxip, deleteXip: deleteXip, noSuperuser: noSuperuser)
201+
return self.install(installationType, dataSource: dataSource, downloader: downloader, destination: destination, attemptNumber: attemptNumber + 1, experimentalUnxip: experimentalUnxip, emptyTrash: emptyTrash, noSuperuser: noSuperuser)
202202
}
203203
}
204204
default:
@@ -531,7 +531,7 @@ public final class XcodeInstaller {
531531
}
532532
}
533533

534-
public func installArchivedXcode(_ xcode: Xcode, at archiveURL: URL, to destination: Path, experimentalUnxip: Bool = false, deleteXip: Bool, noSuperuser: Bool) -> Promise<InstalledXcode> {
534+
public func installArchivedXcode(_ xcode: Xcode, at archiveURL: URL, to destination: Path, experimentalUnxip: Bool = false, emptyTrash: Bool, noSuperuser: Bool) -> Promise<InstalledXcode> {
535535
return firstly { () -> Promise<InstalledXcode> in
536536
let destinationURL = destination.join("Xcode-\(xcode.version.descriptionWithoutBuildMetadata).app").url
537537
switch archiveURL.pathExtension {
@@ -551,8 +551,8 @@ public final class XcodeInstaller {
551551
}
552552
}
553553
.then { xcode -> Promise<InstalledXcode> in
554-
Current.logging.log(InstallationStep.cleaningArchive(archiveName: archiveURL.lastPathComponent, shouldDelete: deleteXip).description)
555-
if deleteXip {
554+
Current.logging.log(InstallationStep.cleaningArchive(archiveName: archiveURL.lastPathComponent, shouldDelete: emptyTrash).description)
555+
if emptyTrash {
556556
try Current.files.removeItem(at: archiveURL)
557557
}
558558
else {
@@ -595,7 +595,7 @@ public final class XcodeInstaller {
595595
}
596596
}
597597

598-
public func uninstallXcode(_ versionString: String, directory: Path, deleteApp: Bool) -> Promise<Void> {
598+
public func uninstallXcode(_ versionString: String, directory: Path, emptyTrash: 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)
@@ -610,7 +610,7 @@ public final class XcodeInstaller {
610610
return Promise.value(installedXcode)
611611
}
612612
.map { installedXcode -> (InstalledXcode, URL?) in
613-
if deleteApp {
613+
if emptyTrash {
614614
try Current.files.removeItem(at: installedXcode.path.url)
615615
return (installedXcode, nil)
616616
}

Sources/xcodes/main.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ struct Xcodes: ParsableCommand {
189189
@Flag(help: "Don't ask for superuser (root) permission. Some optional steps of the installation will be skipped.")
190190
var noSuperuser: Bool = false
191191

192-
@Flag(help: "Completely delete Xcode .xip after installation, instead of moving it to the user's Trash.")
193-
var deleteXip: Bool = false
192+
@Flag(help: "Completely delete Xcode .xip after installation, instead of keeping it on the user's Trash.")
193+
var emptyTrash: Bool = false
194194

195195
@Option(help: "The directory to install Xcode into. Defaults to /Applications.",
196196
completion: .directory)
@@ -227,7 +227,7 @@ struct Xcodes: ParsableCommand {
227227

228228
let destination = getDirectory(possibleDirectory: directory)
229229

230-
installer.install(installation, dataSource: globalDataSource.dataSource, downloader: downloader, destination: destination, experimentalUnxip: experimentalUnxip, deleteXip: deleteXip, noSuperuser: noSuperuser)
230+
installer.install(installation, dataSource: globalDataSource.dataSource, downloader: downloader, destination: destination, experimentalUnxip: experimentalUnxip, emptyTrash: emptyTrash, noSuperuser: noSuperuser)
231231
.done { Install.exit() }
232232
.catch { error in
233233
Install.processDownloadOrInstall(error: error)
@@ -351,8 +351,8 @@ 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
354+
@Flag(help: "Completely delete Xcode, instead of keeping it on the user's Trash.")
355+
var emptyTrash: Bool = false
356356

357357
@OptionGroup
358358
var globalDirectory: GlobalDirectoryOption
@@ -365,7 +365,7 @@ struct Xcodes: ParsableCommand {
365365

366366
let directory = getDirectory(possibleDirectory: globalDirectory.directory)
367367

368-
installer.uninstallXcode(version.joined(separator: " "), directory: directory, deleteApp: deleteApp)
368+
installer.uninstallXcode(version.joined(separator: " "), directory: directory, emptyTrash: emptyTrash)
369369
.done { Uninstall.exit() }
370370
.catch { error in Uninstall.exit(withLegibleError: error) }
371371

Tests/XcodesKitTests/XcodesKitTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ final class XcodesKitTests: XCTestCase {
8686

8787
let xcode = Xcode(version: Version("0.0.0")!, url: URL(fileURLWithPath: "/"), filename: "mock", releaseDate: nil)
8888
let installedXcode = InstalledXcode(path: Path("/Applications/Xcode-0.0.0.app")!)!
89-
installer.installArchivedXcode(xcode, at: URL(fileURLWithPath: "/Xcode-0.0.0.xip"), to: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
89+
installer.installArchivedXcode(xcode, at: URL(fileURLWithPath: "/Xcode-0.0.0.xip"), to: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
9090
.catch { error in XCTAssertEqual(error as! XcodeInstaller.Error, XcodeInstaller.Error.failedSecurityAssessment(xcode: installedXcode, output: "")) }
9191
}
9292

9393
func test_InstallArchivedXcode_VerifySigningCertificateFails_Throws() {
9494
Current.shell.codesignVerify = { _ in return Promise(error: Process.PMKError.execution(process: Process(), standardOutput: nil, standardError: nil)) }
9595

9696
let xcode = Xcode(version: Version("0.0.0")!, url: URL(fileURLWithPath: "/"), filename: "mock", releaseDate: nil)
97-
installer.installArchivedXcode(xcode, at: URL(fileURLWithPath: "/Xcode-0.0.0.xip"), to: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
97+
installer.installArchivedXcode(xcode, at: URL(fileURLWithPath: "/Xcode-0.0.0.xip"), to: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
9898
.catch { error in XCTAssertEqual(error as! XcodeInstaller.Error, XcodeInstaller.Error.codesignVerifyFailed(output: "")) }
9999
}
100100

101101
func test_InstallArchivedXcode_VerifySigningCertificateDoesntMatch_Throws() {
102102
Current.shell.codesignVerify = { _ in return Promise.value((0, "", "")) }
103103

104104
let xcode = Xcode(version: Version("0.0.0")!, url: URL(fileURLWithPath: "/"), filename: "mock", releaseDate: nil)
105-
installer.installArchivedXcode(xcode, at: URL(fileURLWithPath: "/Xcode-0.0.0.xip"), to: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
105+
installer.installArchivedXcode(xcode, at: URL(fileURLWithPath: "/Xcode-0.0.0.xip"), to: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
106106
.catch { error in XCTAssertEqual(error as! XcodeInstaller.Error, XcodeInstaller.Error.unexpectedCodeSigningIdentity(identifier: "", certificateAuthority: [])) }
107107
}
108108

@@ -115,7 +115,7 @@ final class XcodesKitTests: XCTestCase {
115115

116116
let xcode = Xcode(version: Version("0.0.0")!, url: URL(fileURLWithPath: "/"), filename: "mock", releaseDate: nil)
117117
let xipURL = URL(fileURLWithPath: "/Xcode-0.0.0.xip")
118-
installer.installArchivedXcode(xcode, at: xipURL, to: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
118+
installer.installArchivedXcode(xcode, at: xipURL, to: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
119119
.ensure { XCTAssertEqual(trashedItemAtURL, xipURL) }
120120
.cauterize()
121121
}
@@ -203,7 +203,7 @@ final class XcodesKitTests: XCTestCase {
203203

204204
let expectation = self.expectation(description: "Finished")
205205

206-
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
206+
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
207207
.ensure {
208208
let url = Bundle.module.url(forResource: "LogOutput-FullHappyPath", withExtension: "txt", subdirectory: "Fixtures")!
209209
XCTAssertEqual(log, try! String(contentsOf: url))
@@ -296,7 +296,7 @@ final class XcodesKitTests: XCTestCase {
296296

297297
let expectation = self.expectation(description: "Finished")
298298

299-
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
299+
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
300300
.ensure {
301301
let url = Bundle.module.url(forResource: "LogOutput-FullHappyPath-NoColor", withExtension: "txt", subdirectory: "Fixtures")!
302302
XCTAssertEqual(log, try! String(contentsOf: url))
@@ -393,7 +393,7 @@ final class XcodesKitTests: XCTestCase {
393393

394394
let expectation = self.expectation(description: "Finished")
395395

396-
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
396+
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
397397
.ensure {
398398
let url = Bundle.module.url(forResource: "LogOutput-FullHappyPath-NonInteractiveTerminal", withExtension: "txt", subdirectory: "Fixtures")!
399399
XCTAssertEqual(log, try! String(contentsOf: url))
@@ -486,7 +486,7 @@ final class XcodesKitTests: XCTestCase {
486486

487487
let expectation = self.expectation(description: "Finished")
488488

489-
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.home.join("Xcode"), deleteXip: false, noSuperuser: false)
489+
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.home.join("Xcode"), emptyTrash: false, noSuperuser: false)
490490
.ensure {
491491
let url = Bundle.module.url(forResource: "LogOutput-AlternativeDirectory", withExtension: "txt", subdirectory: "Fixtures")!
492492
let expectedText = try! String(contentsOf: url).replacingOccurrences(of: "/Users/brandon", with: Path.home.string)
@@ -600,7 +600,7 @@ final class XcodesKitTests: XCTestCase {
600600

601601
let expectation = self.expectation(description: "Finished")
602602

603-
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
603+
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
604604
.ensure {
605605
let url = Bundle.module.url(forResource: "LogOutput-IncorrectSavedPassword", withExtension: "txt", subdirectory: "Fixtures")!
606606
XCTAssertEqual(log, try! String(contentsOf: url))
@@ -718,7 +718,7 @@ final class XcodesKitTests: XCTestCase {
718718

719719
let expectation = self.expectation(description: "Finished")
720720

721-
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), deleteXip: false, noSuperuser: false)
721+
installer.install(.version("0.0.0"), dataSource: .apple, downloader: .urlSession, destination: Path.root.join("Applications"), emptyTrash: false, noSuperuser: false)
722722
.ensure {
723723
let url = Bundle.module.url(forResource: "LogOutput-DamagedXIP", withExtension: "txt", subdirectory: "Fixtures")!
724724
let expectedText = try! String(contentsOf: url).replacingOccurrences(of: "/Users/brandon", with: Path.home.string)
@@ -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"), deleteApp: false)
781+
installer.uninstallXcode("0.0.0", directory: Path.root.join("Applications"), emptyTrash: 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"), deleteApp: false)
826+
installer.uninstallXcode("999", directory: Path.root.join("Applications"), emptyTrash: false)
827827
.ensure {
828828
XCTAssertEqual(trashedItemAtURL, installedXcodes[0].path.url)
829829
}

0 commit comments

Comments
 (0)