From 3c2906a313ff58ba758e4d21fca2e716a0537488 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Mon, 29 May 2023 15:29:08 -0700 Subject: [PATCH] utmctl: add delete command Resolves #5290 --- utmctl/UTMCtl.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/utmctl/UTMCtl.swift b/utmctl/UTMCtl.swift index c90d362a..46767843 100644 --- a/utmctl/UTMCtl.swift +++ b/utmctl/UTMCtl.swift @@ -24,7 +24,7 @@ struct UTMCtl: ParsableCommand { static var configuration = CommandConfiguration( commandName: "utmctl", 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 { struct VMIdentifier: ParsableArguments { @Argument(help: "Either the UUID or the complete name of the virtual machine.")