mirror of
https://github.com/cirruslabs/tart.git
synced 2026-10-08 23:21:23 +02:00
* Ditch Foundation.exit()'s where feasible * Sentry integration * SwiftFormat * Upload symbols and sources to Sentry * Use Sentry Releases * Do not use ExitCode exceptions * Clarify why we need CustomNSError extension
62 lines
1.4 KiB
Swift
62 lines
1.4 KiB
Swift
import ArgumentParser
|
|
import Foundation
|
|
|
|
struct Set: AsyncParsableCommand {
|
|
static var configuration = CommandConfiguration(commandName: "set", abstract: "Modify VM's configuration")
|
|
|
|
@Argument(help: "VM name")
|
|
var name: String
|
|
|
|
@Option(help: "Number of VM CPUs")
|
|
var cpu: UInt16?
|
|
|
|
@Option(help: "VM memory size in megabytes")
|
|
var memory: UInt64?
|
|
|
|
@Option(help: "VM display resolution in a format of <width>x<height>. For example, 1200x800")
|
|
var display: VMDisplayConfig?
|
|
|
|
@Option(help: .hidden)
|
|
var diskSize: UInt16?
|
|
|
|
func run() async throws {
|
|
let vmDir = try VMStorageLocal().open(name)
|
|
var vmConfig = try VMConfig(fromURL: vmDir.configURL)
|
|
|
|
if let cpu = cpu {
|
|
try vmConfig.setCPU(cpuCount: Int(cpu))
|
|
}
|
|
|
|
if let memory = memory {
|
|
try vmConfig.setMemory(memorySize: memory * 1024 * 1024)
|
|
}
|
|
|
|
if let display = display {
|
|
if (display.width > 0) {
|
|
vmConfig.display.width = display.width
|
|
}
|
|
if (display.height > 0) {
|
|
vmConfig.display.height = display.height
|
|
}
|
|
}
|
|
|
|
try vmConfig.save(toURL: vmDir.configURL)
|
|
|
|
if diskSize != nil {
|
|
try vmDir.resizeDisk(diskSize!)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension VMDisplayConfig: ExpressibleByArgument {
|
|
public init(argument: String) {
|
|
let parts = argument.components(separatedBy: "x").map {
|
|
Int($0) ?? 0
|
|
}
|
|
self = VMDisplayConfig(
|
|
width: parts[safe: 0] ?? 0,
|
|
height: parts[safe: 1] ?? 0
|
|
)
|
|
}
|
|
}
|