utmctl: add clone command

Resolves #5004
This commit is contained in:
osy
2023-04-17 22:21:05 -07:00
parent 7730bec98f
commit d2eb90befe
+24 -1
View File
@@ -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.")