Jelajahi Sumber

utmctl: add version command

For the scripting backend, we have to use a hack. The existing property
`version` cannot be accessed through App Sandbox because the inherited
suite does not define an access-group. We create a new property that is
accessible by the com.utmapp.UTM.vm-access access group.

Resolves #7350
osy 3 hari lalu
induk
melakukan
d5c224b88d
3 mengubah file dengan 19 tambahan dan 0 penghapusan
  1. 3 0
      Scripting/UTM.sdef
  2. 1 0
      Scripting/UTMScripting.swift
  3. 15 0
      utmctl/UTMCtl.swift

+ 3 - 0
Scripting/UTM.sdef

@@ -26,6 +26,9 @@
           <property name="auto terminate" code="kRlW" type="boolean" description="Auto terminate the application when all windows are closed?">
               <cocoa key="isAutoTerminate"/>
           </property>
+          <property name="UTM version" code="UTMv" type="text" access="r" description="The version number of UTM.">
+              <cocoa key="version"/>
+          </property>
         </class-extension>
         
         <enumeration name="backend" code="VmEb" description="Backend type.">

+ 1 - 0
Scripting/UTMScripting.swift

@@ -184,6 +184,7 @@ import ScriptingBridge
     @objc optional func importNew(_ new_: NSNumber!, from: URL!) -> SBObject // Import a new virtual machine from a file.
     @objc optional func virtualMachines() -> SBElementArray
     @objc optional var autoTerminate: Bool { get } // Auto terminate the application when all windows are closed?
+    @objc optional var UTMVersion: String { get } // The version number of UTM.
     @objc optional func setAutoTerminate(_ autoTerminate: Bool) // Auto terminate the application when all windows are closed?
     @objc optional func usbDevices() -> SBElementArray
 }

+ 15 - 0
utmctl/UTMCtl.swift

@@ -25,6 +25,7 @@ struct UTMCtl: ParsableCommand {
         commandName: "utmctl",
         abstract: "CLI tool for controlling UTM virtual machines.",
         subcommands: [
+            Version.self,
             List.self,
             Status.self,
             Start.self,
@@ -165,6 +166,20 @@ fileprivate extension UTMScriptingStatus {
     }
 }
 
+extension UTMCtl {
+    struct Version: UTMAPICommand {
+        static var configuration = CommandConfiguration(
+            abstract: "Display the version number of the application."
+        )
+
+        @OptionGroup var environment: EnvironmentOptions
+
+        func run(with application: UTMScriptingApplication) throws {
+            print("\(application.UTMVersion ?? "")")
+        }
+    }
+}
+
 extension UTMCtl {
     struct List: UTMAPICommand {
         static var configuration = CommandConfiguration(