mirror of
https://github.com/utmapp/UTM.git
synced 2026-10-12 02:24:01 +00:00
utmctl: verbose response on error
This commit is contained in:
@@ -27,14 +27,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
return vmList.contains(where: { $0.state == .vmStarted || ($0.state == .vmPaused && !$0.hasSaveState) })
|
||||
}
|
||||
|
||||
private var isLaunchedByCLI: Bool {
|
||||
if CommandLine.arguments.count > 1 && CommandLine.arguments[1] == "cli-request" {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@objc var scriptingVirtualMachines: [UTMScriptingVirtualMachineImpl] {
|
||||
guard let data = data else {
|
||||
@@ -107,9 +99,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
if isDockIconHidden {
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
}
|
||||
if isLaunchedByCLI && isKeepRunningAfterLastWindowClosed {
|
||||
NSApp.windows.first?.close()
|
||||
}
|
||||
}
|
||||
|
||||
func application(_ sender: NSApplication, delegateHandlesKey key: String) -> Bool {
|
||||
|
||||
@@ -268,7 +268,6 @@
|
||||
84E3A8F3293DB37E0024A740 /* UTMCtl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E3A8F2293DB37E0024A740 /* UTMCtl.swift */; };
|
||||
84E3A8FB293DB7240024A740 /* utmctl in Embed CLI Tool */ = {isa = PBXBuildFile; fileRef = 84E3A8F0293DB37E0024A740 /* utmctl */; };
|
||||
84E3A900293DBC290024A740 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 84E3A8FF293DBC290024A740 /* ArgumentParser */; };
|
||||
84E3A911294469B10024A740 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 84E3A910294469B10024A740 /* Logging */; };
|
||||
84E3A91B2946D2590024A740 /* UTMMenuBarExtraScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E3A91A2946D2590024A740 /* UTMMenuBarExtraScene.swift */; };
|
||||
84E6F6FD289319AE00080EEF /* VMToolbarDisplayMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E6F6FC289319AE00080EEF /* VMToolbarDisplayMenuView.swift */; };
|
||||
84E6F6FE289319AE00080EEF /* VMToolbarDisplayMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E6F6FC289319AE00080EEF /* VMToolbarDisplayMenuView.swift */; };
|
||||
@@ -2334,7 +2333,6 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
84E3A911294469B10024A740 /* Logging in Frameworks */,
|
||||
84E3A900293DBC290024A740 /* ArgumentParser in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -3430,7 +3428,6 @@
|
||||
name = utmctl;
|
||||
packageProductDependencies = (
|
||||
84E3A8FF293DBC290024A740 /* ArgumentParser */,
|
||||
84E3A910294469B10024A740 /* Logging */,
|
||||
);
|
||||
productName = utmctl;
|
||||
productReference = 84E3A8F0293DB37E0024A740 /* utmctl */;
|
||||
@@ -5522,11 +5519,6 @@
|
||||
package = 84E3A8FE293DBC290024A740 /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
|
||||
productName = ArgumentParser;
|
||||
};
|
||||
84E3A910294469B10024A740 /* Logging */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */;
|
||||
productName = Logging;
|
||||
};
|
||||
85EC515B27CC74AA004A51DE /* Logging */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = CE020BA524AEDEF000B44AB6 /* XCRemoteSwiftPackageReference "swift-log" */;
|
||||
|
||||
+15
-13
@@ -17,13 +17,8 @@
|
||||
import Foundation
|
||||
import AppKit
|
||||
import ArgumentParser
|
||||
import Logging
|
||||
import ScriptingBridge
|
||||
|
||||
var logger = Logger(label: "com.utmapp.utmctl") { label in
|
||||
StreamLogHandler.standardError(label: label)
|
||||
}
|
||||
|
||||
@main
|
||||
struct UTMCtl: ParsableCommand {
|
||||
static var configuration = CommandConfiguration(
|
||||
@@ -43,10 +38,10 @@ protocol UTMAPICommand: ParsableCommand {
|
||||
extension UTMAPICommand {
|
||||
/// Entry point for all subcommands
|
||||
func run() throws {
|
||||
logger.logLevel = environment.debug ? .debug : .info
|
||||
guard let utmApp = SBApplication(url: utmAppUrl) else {
|
||||
throw UTMCtl.APIError.applicationNotFound
|
||||
}
|
||||
utmApp.launchFlags = [.defaults, .andHide]
|
||||
utmApp.delegate = UTMCtl.EventErrorHandler.shared
|
||||
try run(with: utmApp)
|
||||
}
|
||||
@@ -86,7 +81,10 @@ extension UTMCtl {
|
||||
/// - error: Error
|
||||
/// - Returns: nil
|
||||
func eventDidFail(_ event: UnsafePointer<AppleEvent>, withError error: Error) -> Any? {
|
||||
logger.error("Error from event: \(error.localizedDescription)")
|
||||
FileHandle.standardError.write("Error from event: \(error.localizedDescription)")
|
||||
if let user = (error as NSError).userInfo["ErrorString"] as? String {
|
||||
FileHandle.standardError.write(user)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -323,12 +321,6 @@ extension UTMCtl {
|
||||
struct EnvironmentOptions: ParsableArguments {
|
||||
@Flag(name: .shortAndLong, help: "Show debug logging.")
|
||||
var debug: Bool = false
|
||||
|
||||
@Flag(name: .shortAndLong, help: "Output results in JSON.")
|
||||
var machineReadable: Bool = false
|
||||
|
||||
@Option(help: "Specify a custom path to the UTM API server socket.")
|
||||
var socketPath: String?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,3 +329,13 @@ private extension String {
|
||||
URL(fileURLWithPath: self, relativeTo: nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension FileHandle: TextOutputStream {
|
||||
private static var newLine = Data("\n".utf8)
|
||||
|
||||
public func write(_ string: String) {
|
||||
let data = Data(string.utf8)
|
||||
self.write(data)
|
||||
self.write(Self.newLine)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user