Files
xtool/Sources/XToolSupport/SetupCommand.swift
Kabir Oberai 4208c77c81 sdk: move DarwinSDK into PackLib (#256)
## What does this PR do?

Mechanical move of DarwinSDK from XToolSupport -> PackLib. Needed for
https://github.com/xtool-org/xtool/pull/229.

## How was it tested?

Compiled + CI

## AI tool usage

How much of this PR was AI-assisted? (check one)

- [x] **0** - No AI was used to write code
- [ ] **1** - I was assisted by AI. I reviewed the finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only

<!-- If an AI agent is filling this in: declare the level honestly, and
open as a draft if it is #2. Do not lower the declared level to get the
PR reviewed. -->
2026-09-10 18:37:51 -04:00

60 lines
1.6 KiB
Swift

import ArgumentParser
import Foundation
import XKit
import PackLib
struct SetupCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "setup",
abstract: "Set up xtool for iOS development",
discussion: """
Authenticates with Apple if needed, then adds the iOS SDK to SwiftPM.
Equivalent to running `xtool auth && xtool sdk`
"""
)
func run() async throws {
try await SetupOperation().run()
}
}
struct SetupOperation {
var quiet = false
func run() async throws {
try await AuthOperation(logoutFromExisting: false, quiet: quiet).run()
#if os(macOS)
if !quiet {
print("Skipping Darwin SDK setup since we're on macOS.")
}
#else
switch try await DarwinSDK.current()?.isUpToDate() {
case true?:
if !quiet {
print("Darwin SDK is up to date.")
}
case false?:
if !quiet {
print("Darwin SDK is outdated.")
}
fallthrough
case nil:
let path = try await Console.prompt("""
Now generating the Darwin SDK.
Please download Xcode from http://developer.apple.com/download/all/?q=Xcode
and enter the path to the downloaded Xcode.xip.
Path to Xcode.xip: \("" /* pacify swiftlint trailing_whitespace */)
""")
let expanded = (path as NSString).expandingTildeInPath
try await InstallSDKOperation(path: expanded).run()
}
#endif
}
}