From 31e7d57e56fad7f74ecfe2a2eca5e22d5f12f2a7 Mon Sep 17 00:00:00 2001 From: Bill Gestrich <3207996+gestrich@users.noreply.github.com> Date: Sun, 5 Nov 2023 16:17:15 -0500 Subject: [PATCH] Use swift concurrency --- Package.swift | 5 ++++- Sources/swift-utilities/CommandLineAction.swift | 10 ++++------ Sources/swift-utilities/CommandLineUtils.swift | 10 +++------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Package.swift b/Package.swift index a16c6f0..203dffe 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,13 @@ -// swift-tools-version:5.2 +// swift-tools-version:5.6 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "swift-utilities", + platforms: [ + .macOS(.v10_15) + ], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( diff --git a/Sources/swift-utilities/CommandLineAction.swift b/Sources/swift-utilities/CommandLineAction.swift index 33d0296..636723d 100644 --- a/Sources/swift-utilities/CommandLineAction.swift +++ b/Sources/swift-utilities/CommandLineAction.swift @@ -8,13 +8,11 @@ import Foundation public struct CommandLineAction { - public let longName: String - public let shortName: String? - public let action: () throws -> Void + public let name: String + public let action: () async throws -> Void - public init(longName: String, shortName: String? = nil, action: @escaping () throws -> Void) { - self.longName = longName - self.shortName = shortName + public init(actionName: String, action: @escaping () async throws -> Void) { + self.name = actionName self.action = action } diff --git a/Sources/swift-utilities/CommandLineUtils.swift b/Sources/swift-utilities/CommandLineUtils.swift index b066abd..266eadf 100644 --- a/Sources/swift-utilities/CommandLineUtils.swift +++ b/Sources/swift-utilities/CommandLineUtils.swift @@ -123,15 +123,11 @@ public func getEnvironmentVariable(key: String) -> String? { //MARK: Text Input -public func promptForAction(title: String = "Select Option", actions: [CommandLineAction]) throws { +public func promptForAction(title: String = "Select Option", actions: [CommandLineAction]) async throws { let selection = promptForSelection(title: title, displayOneBasedIndex: true, options: actions.map({ - var option = $0.longName - if let shortName = $0.shortName { - option = "\(option) (-\(shortName))" - } - return option + $0.name })) - try actions[selection].action() + try await actions[selection].action() } public func promptForSelection(title: String, displayOneBasedIndex: Bool = false, options: [String]) -> Int {