mirror of https://github.com/cirruslabs/tart.git
Update dependencies and styles (#12)
* Update deps and .editorconfig * run config
This commit is contained in:
parent
dc1e502404
commit
49d430b3c4
|
|
@ -0,0 +1,6 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="tart run" type="SwiftPackageManagerRunConfiguration" factoryName="Swift Package Run" PROGRAM_PARAMS="run latest" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="tart" TARGET_NAME="tart" CONFIG_NAME="tart" RUN_TARGET_PROJECT_NAME="tart" RUN_TARGET_NAME="tart" WAS_MODIFIED="">
|
||||
<method v="2">
|
||||
<option name="SPM.BUILD_TASK_PROVIDER" enabled="true" />
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="sign debug" run_configuration_type="ShConfigurationType" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/apple/swift-argument-parser",
|
||||
"state" : {
|
||||
"revision" : "e394bf350e38cb100b6bc4172834770ede1b7232",
|
||||
"version" : "1.0.3"
|
||||
"revision" : "82905286cc3f0fa8adc4674bf49437cab65a8373",
|
||||
"version" : "1.1.1"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ let package = Package(
|
|||
.macOS(.v12)
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.3"),
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.1.1"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(name: "tart",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import Foundation
|
|||
import SystemConfiguration
|
||||
import Virtualization
|
||||
|
||||
struct Clone: ParsableCommand {
|
||||
struct Clone: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "Clone a VM")
|
||||
|
||||
@Argument(help: "source VM name")
|
||||
|
|
@ -12,8 +12,7 @@ struct Clone: ParsableCommand {
|
|||
@Argument(help: "new VM name")
|
||||
var newName: String
|
||||
|
||||
func run() throws {
|
||||
Task {
|
||||
func run() async throws {
|
||||
do {
|
||||
let vmStorage = VMStorage()
|
||||
let sourceVMDir = try vmStorage.read(sourceName)
|
||||
|
|
@ -34,7 +33,4 @@ struct Clone: ParsableCommand {
|
|||
Foundation.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
dispatchMain()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import Dispatch
|
|||
import SwiftUI
|
||||
import Foundation
|
||||
|
||||
struct Create: ParsableCommand {
|
||||
struct Create: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "Create a VM")
|
||||
|
||||
@Argument(help: "VM name")
|
||||
|
|
@ -17,8 +17,7 @@ struct Create: ParsableCommand {
|
|||
}
|
||||
}
|
||||
|
||||
func run() throws {
|
||||
Task {
|
||||
func run() async throws {
|
||||
do {
|
||||
let vmDir = try VMStorage().create(name)
|
||||
|
||||
|
|
@ -35,7 +34,4 @@ struct Create: ParsableCommand {
|
|||
Foundation.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
dispatchMain()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@ import ArgumentParser
|
|||
import Dispatch
|
||||
import SwiftUI
|
||||
|
||||
struct Delete: ParsableCommand {
|
||||
struct Delete: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "Delete a VM")
|
||||
|
||||
@Argument(help: "VM name")
|
||||
var name: String
|
||||
|
||||
func run() throws {
|
||||
Task {
|
||||
func run() async throws {
|
||||
do {
|
||||
try VMStorage().delete(name)
|
||||
|
||||
|
|
@ -20,7 +19,4 @@ struct Delete: ParsableCommand {
|
|||
Foundation.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
dispatchMain()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@ import ArgumentParser
|
|||
import Foundation
|
||||
import SystemConfiguration
|
||||
|
||||
struct IP: ParsableCommand {
|
||||
struct IP: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "Get VM's IP address")
|
||||
|
||||
@Argument(help: "VM name")
|
||||
var name: String
|
||||
|
||||
func run() throws {
|
||||
Task {
|
||||
func run() async throws {
|
||||
do {
|
||||
let vmDir = try VMStorage().read(name)
|
||||
let vmConfig = try VMConfig.init(fromURL: vmDir.configURL)
|
||||
|
|
@ -30,7 +29,4 @@ struct IP: ParsableCommand {
|
|||
Foundation.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
dispatchMain()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ import ArgumentParser
|
|||
import Dispatch
|
||||
import SwiftUI
|
||||
|
||||
struct List: ParsableCommand {
|
||||
struct List: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "List created VMs")
|
||||
|
||||
func run() throws {
|
||||
Task {
|
||||
func run() async throws {
|
||||
do {
|
||||
for vmURL in try VMStorage().list() {
|
||||
print(vmURL)
|
||||
|
|
@ -19,7 +18,4 @@ struct List: ParsableCommand {
|
|||
Foundation.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
dispatchMain()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
import ArgumentParser
|
||||
|
||||
struct Root: ParsableCommand {
|
||||
static var configuration = CommandConfiguration(
|
||||
commandName: "tart",
|
||||
subcommands: [Create.self, Clone.self, Run.self, List.self, IP.self, Delete.self])
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import Virtualization
|
|||
|
||||
var vm: VM?
|
||||
|
||||
struct Run: ParsableCommand {
|
||||
struct Run: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(abstract: "Run a VM")
|
||||
|
||||
@Argument(help: "VM name")
|
||||
|
|
@ -13,7 +13,7 @@ struct Run: ParsableCommand {
|
|||
|
||||
@Flag var noGraphics: Bool = false
|
||||
|
||||
func run() throws {
|
||||
func run() async throws {
|
||||
let vmDir = try VMStorage().read(name)
|
||||
vm = try VM(vmDir: vmDir)
|
||||
|
||||
|
|
@ -33,9 +33,9 @@ struct Run: ParsableCommand {
|
|||
dispatchMain()
|
||||
} else {
|
||||
// UI mumbo-jumbo
|
||||
let nsApp = NSApplication.shared
|
||||
nsApp.setActivationPolicy(.regular)
|
||||
nsApp.activate(ignoringOtherApps: true)
|
||||
let nsApp = await NSApplication.shared
|
||||
await nsApp.setActivationPolicy(.regular)
|
||||
await nsApp.activate(ignoringOtherApps: true)
|
||||
|
||||
struct MainApp: App {
|
||||
var body: some Scene {
|
||||
|
|
@ -45,7 +45,7 @@ struct Run: ParsableCommand {
|
|||
}
|
||||
}
|
||||
|
||||
MainApp.main()
|
||||
await MainApp.main()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
import ArgumentParser
|
||||
|
||||
@main
|
||||
struct Root: AsyncParsableCommand {
|
||||
static var configuration = CommandConfiguration(
|
||||
commandName: "tart",
|
||||
subcommands: [Create.self, Clone.self, Run.self, List.self, IP.self, Delete.self])
|
||||
}
|
||||
|
|
@ -1,9 +1,14 @@
|
|||
import Foundation
|
||||
import Virtualization
|
||||
|
||||
struct UnsupportedRestoreImageError: Error {}
|
||||
struct NoMainScreenFoundError: Error {}
|
||||
struct DownloadFailed: Error {}
|
||||
struct UnsupportedRestoreImageError: Error {
|
||||
}
|
||||
|
||||
struct NoMainScreenFoundError: Error {
|
||||
}
|
||||
|
||||
struct DownloadFailed: Error {
|
||||
}
|
||||
|
||||
class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
|
||||
// Virtualization.Framework's virtual machine
|
||||
|
|
@ -40,7 +45,9 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
|
|||
static func retrieveLatestIPSW() async throws -> URL {
|
||||
defaultLogger.appendNewLine("Looking up the latest supported IPSW...")
|
||||
let image = try await withCheckedThrowingContinuation { continuation in
|
||||
VZMacOSRestoreImage.fetchLatestSupported() { result in continuation.resume(with: result) }
|
||||
VZMacOSRestoreImage.fetchLatestSupported() { result in
|
||||
continuation.resume(with: result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -82,10 +89,14 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
|
|||
// Load the restore image and try to get the requirements
|
||||
// that match both the image and our platform
|
||||
let image = try await withCheckedThrowingContinuation { continuation in
|
||||
VZMacOSRestoreImage.load(from: ipswURL) { result in continuation.resume(with: result) }
|
||||
VZMacOSRestoreImage.load(from: ipswURL) { result in
|
||||
continuation.resume(with: result)
|
||||
}
|
||||
}
|
||||
|
||||
guard let requirements = image.mostFeaturefulSupportedConfiguration else { throw UnsupportedRestoreImageError() }
|
||||
guard let requirements = image.mostFeaturefulSupportedConfiguration else {
|
||||
throw UnsupportedRestoreImageError()
|
||||
}
|
||||
|
||||
// Create NVRAM
|
||||
let auxStorage = try VZMacAuxiliaryStorage(creatingStorageAt: vmDir.nvramURL, hardwareModel: requirements.hardwareModel)
|
||||
|
|
@ -128,7 +139,9 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
|
|||
defaultLogger.appendNewLine("Installing OS...")
|
||||
ProgressObserver(installer.progress).log(defaultLogger)
|
||||
|
||||
installer.install { result in continuation.resume(with: result) }
|
||||
installer.install { result in
|
||||
continuation.resume(with: result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
import Foundation
|
||||
|
||||
struct UninitializedVMDirectoryError: Error {}
|
||||
struct AlreadyInitializedVMDirectoryError: Error {}
|
||||
struct UninitializedVMDirectoryError: Error {
|
||||
}
|
||||
|
||||
struct AlreadyInitializedVMDirectoryError: Error {
|
||||
}
|
||||
|
||||
struct VMDirectory {
|
||||
var baseURL: URL
|
||||
|
||||
var configURL: URL { self.baseURL.appendingPathComponent("config.json") }
|
||||
var diskURL: URL { self.baseURL.appendingPathComponent("disk.bin") }
|
||||
var nvramURL: URL { self.baseURL.appendingPathComponent("nvram.bin") }
|
||||
var configURL: URL {
|
||||
self.baseURL.appendingPathComponent("config.json")
|
||||
}
|
||||
var diskURL: URL {
|
||||
self.baseURL.appendingPathComponent("disk.bin")
|
||||
}
|
||||
var nvramURL: URL {
|
||||
self.baseURL.appendingPathComponent("nvram.bin")
|
||||
}
|
||||
|
||||
var initialized: Bool {
|
||||
FileManager.default.fileExists(atPath: configURL.path) &&
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
import SwiftUI
|
||||
|
||||
Root.main()
|
||||
Loading…
Reference in New Issue