diff --git a/Sources/tart/Commands/Get.swift b/Sources/tart/Commands/Get.swift index 91812ed..d195371 100644 --- a/Sources/tart/Commands/Get.swift +++ b/Sources/tart/Commands/Get.swift @@ -9,6 +9,7 @@ fileprivate struct VMInfo: Encodable { let DiskFormat: String let Size: HumanReadableByteCount let Display: String + let MACAddress: String let Running: Bool let State: String } @@ -38,6 +39,7 @@ struct Get: AsyncParsableCommand { String(format: "%.3f", Float($0) / 1000 / 1000 / 1000) }, Display: vmConfig.display.description, + MACAddress: vmConfig.macAddress.string, Running: try vmDir.running(), State: try vmDir.state().rawValue ) diff --git a/Sources/tart/Commands/Set.swift b/Sources/tart/Commands/Set.swift index 389c6d5..cdde2f2 100644 --- a/Sources/tart/Commands/Set.swift +++ b/Sources/tart/Commands/Set.swift @@ -20,6 +20,9 @@ struct Set: AsyncParsableCommand { @Flag(inversion: .prefixedNo, help: ArgumentHelp("Whether to automatically reconfigure the VM's display to fit the window")) var displayRefit: Bool? = nil + @Option(help: ArgumentHelp("MAC address to use.")) + var mac: String? + @Flag(help: ArgumentHelp("Generate a new random MAC address for the VM.")) var randomMAC: Bool = false @@ -47,6 +50,10 @@ struct Set: AsyncParsableCommand { throw ValidationError("--disk is not supported for VMs with a stacked disk") } + if randomMAC && mac != nil { + throw ValidationError("--random-mac and --mac are mutually exclusive") + } + var vmConfig = try VMConfig(fromURL: vmDir.configURL) if let cpu = cpu { @@ -71,6 +78,14 @@ struct Set: AsyncParsableCommand { vmConfig.displayRefit = displayRefit } + if let mac = mac { + if let macAddress = VZMACAddress.init(string: mac), macAddress.isUnicastAddress { + vmConfig.macAddress = macAddress + } else { + throw ValidationError("'\(mac)' is not a valid unicast MAC address") + } + } + if randomMAC { vmConfig.macAddress = VZMACAddress.randomLocallyAdministered() }