Ver Fonte

utmctl: add delete command

Resolves #5290
osy há 2 anos atrás
pai
commit
3c2906a313
1 ficheiros alterados com 18 adições e 1 exclusões
  1. 18 1
      utmctl/UTMCtl.swift

+ 18 - 1
utmctl/UTMCtl.swift

@@ -24,7 +24,7 @@ struct UTMCtl: ParsableCommand {
     static var configuration = CommandConfiguration(
     static var configuration = CommandConfiguration(
         commandName: "utmctl",
         commandName: "utmctl",
         abstract: "CLI tool for controlling UTM virtual machines.",
         abstract: "CLI tool for controlling UTM virtual machines.",
-        subcommands: [List.self, Status.self, Start.self, Suspend.self, Stop.self, Attach.self, File.self, Exec.self, IPAddress.self, Clone.self]
+        subcommands: [List.self, Status.self, Start.self, Suspend.self, Stop.self, Attach.self, File.self, Exec.self, IPAddress.self, Clone.self, Delete.self]
     )
     )
 }
 }
 
 
@@ -484,6 +484,23 @@ extension UTMCtl {
     }
     }
 }
 }
 
 
+extension UTMCtl {
+    struct Delete: UTMAPICommand {
+        static var configuration = CommandConfiguration(
+            abstract: "Delete a virtual machine (there is no confirmation)."
+        )
+        
+        @OptionGroup var environment: EnvironmentOptions
+        
+        @OptionGroup var identifer: VMIdentifier
+        
+        func run(with application: UTMScriptingApplication) throws {
+            let vm = try virtualMachine(forIdentifier: identifer, in: application)
+            vm.delete!()
+        }
+    }
+}
+
 extension UTMCtl {
 extension UTMCtl {
     struct VMIdentifier: ParsableArguments {
     struct VMIdentifier: ParsableArguments {
         @Argument(help: "Either the UUID or the complete name of the virtual machine.")
         @Argument(help: "Either the UUID or the complete name of the virtual machine.")