Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/xcodes/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func getDirectory(possibleDirectory: String?, default: Path = Path.root.join("Ap
return directory
}

/// Resolves the `--path` argument of `install`, treating relative paths as relative to the current directory.
func xipPath(from pathString: String?) -> Path? {
pathString.map { Path($0) ?? Path.cwd/$0 }
}

struct GlobalDirectoryOption: ParsableArguments {
@Option(help: "The directory where your Xcodes are installed. Defaults to /Applications.",
completion: .directory)
Expand Down Expand Up @@ -277,7 +282,7 @@ struct Xcodes: AsyncParsableCommand {
installation = .latest
} else if latestPrerelease {
installation = .latestPrerelease
} else if let pathString = pathString, let path = Path(pathString) {
} else if let path = xipPath(from: pathString) {
installation = .path(versionString, path)
} else {
installation = .version(versionString)
Expand Down
18 changes: 18 additions & 0 deletions Tests/xcodesTests/XipPathTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import XCTest
import Path
@testable import xcodes

final class XipPathTests: XCTestCase {
func test_xipPath_nilWhenNoPathIsGiven() {
XCTAssertNil(xipPath(from: nil))
}

func test_xipPath_keepsAbsolutePath() {
XCTAssertEqual(xipPath(from: "/tmp/Xcode-14.0.0.xip"), Path.root/"tmp/Xcode-14.0.0.xip")
}

func test_xipPath_resolvesRelativePathAgainstCurrentDirectory() {
XCTAssertEqual(xipPath(from: "Xcode-14.0.0.xip"), Path.cwd/"Xcode-14.0.0.xip")
XCTAssertEqual(xipPath(from: "Downloads/Xcode-14.0.0.xip"), Path.cwd/"Downloads/Xcode-14.0.0.xip")
}
}