mirror of
https://github.com/Lakr233/vphone-cli.git
synced 2026-09-02 02:34:29 +00:00
vphone-cli: Add network to vm info/vm list JSON
`vm info --json` and `vm list --json` encode VPhoneBundleReport, which carried no network field — so the network mode was absent from JSON even though the human-readable output prints `net:`. Consumers parsing JSON had no way to read a VM's network config. Project the manifest's NetworkConfig into VPhoneBundleReport as `network`, so both `info` and `list` emit it as structured JSON (mode, macAddress, bridgeInterface). NetworkConfig gains Equatable (VPhoneBundleReport is Equatable). The text `net:` line now reads from the same report projection. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
committed by
zqxwce
co-authored by
Claude Fable 5
parent
aeba01f13c
commit
d37c06b61d
@@ -5,6 +5,7 @@ public struct VPhoneBundleReport: Codable, Equatable, Sendable {
|
||||
public let cpuCount: Int
|
||||
public let memoryMB: Int
|
||||
public let diskSizeBytes: Int64
|
||||
public let network: VPhoneVirtualMachineManifest.NetworkConfig
|
||||
public let restoreInfo: VPhoneRestoreInfo?
|
||||
public let udid: String?
|
||||
|
||||
@@ -13,6 +14,7 @@ public struct VPhoneBundleReport: Codable, Equatable, Sendable {
|
||||
self.cpuCount = Int(bundle.manifest.cpuCount)
|
||||
self.memoryMB = Int(bundle.manifest.memorySize / (1024 * 1024))
|
||||
self.diskSizeBytes = bundle.diskSizeBytes
|
||||
self.network = bundle.manifest.networkConfig
|
||||
self.restoreInfo = VPhoneRestoreInfo.load(fromBundle: bundle)
|
||||
self.udid = VPhoneRestoreOps.resolveUDID(bundle: bundle)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct NetworkConfig: Codable, Sendable {
|
||||
public struct NetworkConfig: Codable, Equatable, Sendable {
|
||||
public let mode: NetworkMode
|
||||
public let macAddress: String
|
||||
/// Host interface identifier to bridge (bridged mode only); nil otherwise.
|
||||
|
||||
@@ -90,7 +90,7 @@ struct VPhoneVMInfoCommand: ParsableCommand {
|
||||
print("cpu: \(report.cpuCount)")
|
||||
print("mem: \(report.memoryMB) MB")
|
||||
print("disk: \(report.diskSizeBytes) bytes")
|
||||
print("net: \(describeNetwork(bundle.manifest.networkConfig))")
|
||||
print("net: \(describeNetwork(report.network))")
|
||||
if let udid = report.udid { print("udid: \(udid)") }
|
||||
if let info = report.restoreInfo {
|
||||
print("iOS: \(info.ios.version) (\(info.ios.build))")
|
||||
|
||||
@@ -13,6 +13,24 @@ struct BundleReportTests {
|
||||
#expect(report.name == "myvm")
|
||||
#expect(report.cpuCount == 6)
|
||||
#expect(report.memoryMB == 4096)
|
||||
#expect(report.network.mode == .nat)
|
||||
}
|
||||
|
||||
@Test func carriesNetworkConfig() throws {
|
||||
let net = VPhoneVirtualMachineManifest.NetworkConfig(
|
||||
mode: .bridged, macAddress: "00:11:22:33:44:55", bridgeInterface: "en0")
|
||||
let manifest = VPhoneVirtualMachineManifest(
|
||||
cpuCount: 2, memorySize: 2 * 1024 * 1024 * 1024,
|
||||
networkConfig: net,
|
||||
romImages: .init(avpBooter: "a", avpSEPBooter: "b"))
|
||||
let report = VPhoneBundleReport(
|
||||
bundle: VPhoneBundle(url: URL(fileURLWithPath: "/tmp/b"), manifest: manifest))
|
||||
#expect(report.network.mode == .bridged)
|
||||
#expect(report.network.bridgeInterface == "en0")
|
||||
|
||||
let back = try JSONDecoder().decode(
|
||||
VPhoneBundleReport.self, from: try JSONEncoder().encode(report))
|
||||
#expect(back.network == net)
|
||||
}
|
||||
|
||||
@Test func encodesToJSON() throws {
|
||||
|
||||
Reference in New Issue
Block a user