-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New argument system and attempt for v0.0.1
- Loading branch information
Showing
7 changed files
with
130 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// Constants.swift | ||
// virtual | ||
// | ||
// Created by Kenneth Endfinger on 11/27/20. | ||
// | ||
|
||
import Foundation | ||
|
||
let virtualToolVersion = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// VirtualCommandRun.swift | ||
// virtual | ||
// | ||
// Created by Kenneth Endfinger on 11/27/20. | ||
// | ||
|
||
import ArgumentParser | ||
import Foundation | ||
import Virtualization | ||
|
||
struct VirtualCommandRun: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
commandName: "run", | ||
abstract: "Run a Linux Virtual Machine" | ||
) | ||
|
||
@Option(name: .shortAndLong, help: "Kernel Path") | ||
var kernel: String | ||
|
||
@Option(name: .shortAndLong, help: "Initial Ramdisk") | ||
var ramdisk: String = "" | ||
|
||
@Option(name: .shortAndLong, help: "Disk Image") | ||
var disk: [String] = [] | ||
|
||
@Option(name: .shortAndLong, help: "Kernel Command Line") | ||
var cmdline: String = "" | ||
|
||
@Option(name: .shortAndLong, help: "CPU Core Count") | ||
var processors: Int = 4 | ||
|
||
@Option(name: .shortAndLong, help: "Machine Memory") | ||
var memory: Int = 2048 | ||
|
||
@Flag(name: .shortAndLong, help: "Enable NAT Networking") | ||
var network: Bool = false | ||
|
||
@Flag(name: .long, help: "Show Version Information") | ||
var version: Bool = false | ||
|
||
mutating func run() throws { | ||
if version { | ||
print("virtual version \(virtualToolVersion)") | ||
VirtualCommand.exit() | ||
} | ||
|
||
enableRawMode(fileHandle: FileHandle.standardInput) | ||
|
||
let system = VirtualSystem(command: self) | ||
do { | ||
try system.start() | ||
|
||
var lastState: VZVirtualMachine.State = .stopped | ||
while system.machine != nil { | ||
let currentState = system.machine!.state | ||
if currentState != lastState { | ||
NSLog("Virtual Machine State: \(system.stateToString())") | ||
lastState = currentState | ||
} | ||
|
||
if currentState == .error { | ||
VirtualCommand.exit() | ||
} | ||
|
||
sleep(1) | ||
} | ||
} catch { | ||
NSLog("\(error)") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// VirtualVersionOptions.swift | ||
// virtual | ||
// | ||
// Created by Kenneth Endfinger on 11/27/20. | ||
// | ||
|
||
import ArgumentParser | ||
|
||
struct VirtualVersionOptions: ParsableArguments { | ||
@Flag(name: .long, help: "Show the Tool Version") | ||
var version: Bool = false | ||
|
||
func validate() throws { | ||
if version { | ||
print(virtualToolVersion) | ||
throw ExitCode.success | ||
} | ||
} | ||
} |