From d43387159ac4f221816655a326f5d6cda2b514ed Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Tue, 9 Apr 2024 00:55:08 +0100 Subject: [PATCH] add VM completion for run command --- Sources/tart/Commands/Run.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index 84e3e28a..6ae08357 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -11,10 +11,18 @@ var vm: VM? struct IPNotFound: Error { } +func completeVM(_ args: [String]) -> [String] { + if let vms = try? VMStorageLocal().list() { + return vms.map { (name, _) in return name } + } + return [] +} + + struct Run: AsyncParsableCommand { static var configuration = CommandConfiguration(abstract: "Run a VM") - @Argument(help: "VM name") + @Argument(help: "VM name", completion: .custom(completeVM)) var name: String @Flag(help: ArgumentHelp(