Files
xtool-mirror/Sources/XToolSupport/SetupCommand.swift
2025-05-06 12:31:48 +05:30

53 lines
1.4 KiB
Swift

import ArgumentParser
import Foundation
import XKit
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()
switch try 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:
""")
let expanded = (path as NSString).expandingTildeInPath
try await InstallSDKOperation(path: expanded).run()
}
}
}