From d2eb90befebdab39500b94f39ce54db4ec6822a9 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Mon, 17 Apr 2023 22:21:05 -0700 Subject: [PATCH] utmctl: add clone command Resolves #5004 --- utmctl/UTMCtl.swift | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/utmctl/UTMCtl.swift b/utmctl/UTMCtl.swift index c17d32e7..c90d362a 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] + subcommands: [List.self, Status.self, Start.self, Suspend.self, Stop.self, Attach.self, File.self, Exec.self, IPAddress.self, Clone.self] ) } @@ -461,6 +461,29 @@ extension UTMCtl { } } +extension UTMCtl { + struct Clone: UTMAPICommand { + static var configuration = CommandConfiguration( + abstract: "Clone an existing virtual machine." + ) + + @OptionGroup var environment: EnvironmentOptions + + @OptionGroup var identifer: VMIdentifier + + @Option var name: String? + + func run(with application: UTMScriptingApplication) throws { + let vm = try virtualMachine(forIdentifier: identifer, in: application) + var properties = ["configuration": [:]] + if let name = name { + properties["configuration"] = ["name": name] + } + vm.duplicateTo!(nil, withProperties: properties) + } + } +} + extension UTMCtl { struct VMIdentifier: ParsableArguments { @Argument(help: "Either the UUID or the complete name of the virtual machine.")