From f37372da2850acb51690f6f212ae8faaa841f400 Mon Sep 17 00:00:00 2001 From: Evan Burkey <106615607+evanburkeyhl@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:14:14 -0800 Subject: [PATCH] Implement Get command (#309) --- Sources/tart/Commands/Get.swift | 31 +++++++++++++++++++++++++++++++ Sources/tart/Root.swift | 1 + 2 files changed, 32 insertions(+) create mode 100644 Sources/tart/Commands/Get.swift diff --git a/Sources/tart/Commands/Get.swift b/Sources/tart/Commands/Get.swift new file mode 100644 index 0000000..3f9aafc --- /dev/null +++ b/Sources/tart/Commands/Get.swift @@ -0,0 +1,31 @@ +import ArgumentParser +import Foundation + +struct Get: AsyncParsableCommand { + static var configuration = CommandConfiguration(commandName: "get", abstract: "Get a VM's configuration") + + @Argument(help: "VM name") + var name: String + + func run() async throws { + do { + let vmDir = try VMStorageLocal().open(name) + let vmConfig = try VMConfig(fromURL: vmDir.configURL) + let diskSize = try vmDir.sizeBytes() / 1000 / 1000 / 1000 + + print("CPU\tMemory\tDisk\tDisplay") + + var s = "\(vmConfig.cpuCount)\t" + s += "\(vmConfig.memorySize / 1024 / 1024) MB\t" + s += "\(diskSize) GB\t" + s += "\(vmConfig.display.width)x\(vmConfig.display.height)" + print(s) + + Foundation.exit(0) + } catch { + print(error) + + Foundation.exit(1) + } + } +} diff --git a/Sources/tart/Root.swift b/Sources/tart/Root.swift index 24350e5..86845fd 100644 --- a/Sources/tart/Root.swift +++ b/Sources/tart/Root.swift @@ -20,6 +20,7 @@ struct Root: AsyncParsableCommand { Clone.self, Run.self, Set.self, + Get.self, List.self, Login.self, IP.self,