utmctl: support booting into recovery mode

This commit is contained in:
user
2025-04-16 12:16:49 +02:00
parent 098e2e27d8
commit d5402b7735
4 changed files with 22 additions and 4 deletions
+13 -1
View File
@@ -111,15 +111,27 @@ class UTMScriptingVirtualMachineImpl: NSObject, UTMScriptable {
@objc func start(_ command: NSScriptCommand) {
let shouldSaveState = command.evaluatedArguments?["saveFlag"] as? Bool ?? true
let bootRecoveryMode = command.evaluatedArguments?["bootRecoveryFlag"] as? Bool ?? false
withScriptCommand(command) { [self] in
var options: UTMVirtualMachineStartOptions = []
if !shouldSaveState {
guard type(of: vm).capabilities.supportsDisposibleMode else {
throw ScriptingError.operationNotSupported
}
options.insert(.bootDisposibleMode)
}
if bootRecoveryMode {
guard type(of: vm).capabilities.supportsRecoveryMode else {
throw ScriptingError.operationNotSupported
}
options.insert(.bootRecovery)
}
data.run(vm: box, startImmediately: false)
if vm.state == .stopped {
try await vm.start(options: shouldSaveState ? [] : .bootDisposibleMode)
try await vm.start(options: options)
} else if vm.state == .paused {
try await vm.resume()
} else {