From b5e58dba4e76d2c06428c31975235268a5c8c819 Mon Sep 17 00:00:00 2001 From: belkhadir Date: Wed, 9 Jul 2025 18:32:49 +0100 Subject: [PATCH 1/3] Remove unnecessary 'await' where no async operations occur --- Sources/MacOSPlatform/MacOS.swift | 2 +- Sources/SwiftlyCore/ModeledCommandLine.swift | 2 +- Tools/generate-command-models/GenerateCommandModels.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/MacOSPlatform/MacOS.swift b/Sources/MacOSPlatform/MacOS.swift index fc2ee67e..088512f8 100644 --- a/Sources/MacOSPlatform/MacOS.swift +++ b/Sources/MacOSPlatform/MacOS.swift @@ -117,7 +117,7 @@ public struct MacOS: Platform { if ctx.mockedHomeDir == nil { await ctx.message("Extracting the swiftly package...") - try await sys.installer( + sys.installer( .pkg(archive), .target("CurrentUserHomeDirectory") ) diff --git a/Sources/SwiftlyCore/ModeledCommandLine.swift b/Sources/SwiftlyCore/ModeledCommandLine.swift index c291f13b..10be5173 100644 --- a/Sources/SwiftlyCore/ModeledCommandLine.swift +++ b/Sources/SwiftlyCore/ModeledCommandLine.swift @@ -181,7 +181,7 @@ extension Runnable { newEnv = newValue } - try await p.runProgram([executable] + args, quiet: quiet, env: newEnv) + try p.runProgram([executable] + args, quiet: quiet, env: newEnv) } } diff --git a/Tools/generate-command-models/GenerateCommandModels.swift b/Tools/generate-command-models/GenerateCommandModels.swift index f7fd99e7..738ba924 100644 --- a/Tools/generate-command-models/GenerateCommandModels.swift +++ b/Tools/generate-command-models/GenerateCommandModels.swift @@ -70,7 +70,7 @@ struct GenerateCommandModels: AsyncParsableCommand { """ } - try await allCmds.write(to: URL(fileURLWithPath: self.outputFile), atomically: true, encoding: .utf8) + try allCmds.write(to: URL(fileURLWithPath: self.outputFile), atomically: true, encoding: .utf8) } struct Vars { From ed0160eed2bbf0d864ea5db4b12ed7ceaed0b248 Mon Sep 17 00:00:00 2001 From: belkhadir Date: Wed, 9 Jul 2025 19:01:17 +0100 Subject: [PATCH 2/3] Silence unused variable warnings --- Sources/MacOSPlatform/MacOS.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/MacOSPlatform/MacOS.swift b/Sources/MacOSPlatform/MacOS.swift index 088512f8..dfbf2fd5 100644 --- a/Sources/MacOSPlatform/MacOS.swift +++ b/Sources/MacOSPlatform/MacOS.swift @@ -117,7 +117,7 @@ public struct MacOS: Platform { if ctx.mockedHomeDir == nil { await ctx.message("Extracting the swiftly package...") - sys.installer( + _ = sys.installer( .pkg(archive), .target("CurrentUserHomeDirectory") ) @@ -193,7 +193,7 @@ public struct MacOS: Platform { } public func getShell() async throws -> String { - for (key, value) in try await sys.dscl(datasource: ".").read(path: fs.home, key: ["UserShell"]).properties(self) { + for (_, value) in try await sys.dscl(datasource: ".").read(path: fs.home, key: ["UserShell"]).properties(self) { return value } From b34d67f11b9978192d87b3166795d1eb9fafa958 Mon Sep 17 00:00:00 2001 From: belkhadir Date: Wed, 9 Jul 2025 19:03:44 +0100 Subject: [PATCH 3/3] Refactor argument name extraction to eliminate warning Replaced multiple `filter(...).first` calls with a single `compactMap(...).first` to simplify logic and eliminate compiler warnings related to unwrapped optionals and unused bindings. The new implementation is more concise and performs better. --- .../GenerateCommandModels.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Tools/generate-command-models/GenerateCommandModels.swift b/Tools/generate-command-models/GenerateCommandModels.swift index 738ba924..0c88265b 100644 --- a/Tools/generate-command-models/GenerateCommandModels.swift +++ b/Tools/generate-command-models/GenerateCommandModels.swift @@ -176,14 +176,12 @@ struct GenerateCommandModels: AsyncParsableCommand { private func argSwitchCase(_ arg: ArgumentInfoV0) -> String { let flag = arg.kind == .flag - var name: String? - if let longName = arg.names?.filter { $0.kind == .long }.first?.name { - name = "--" + longName - } else if let shortName = arg.names?.filter { $0.kind == .short }.first?.name { - name = "-" + shortName - } else if let longNameWithSingleDash = arg.names?.filter { $0.kind == .longWithSingleDash }.first?.name { - name = "-" + longNameWithSingleDash - } + let name: String? = arg.names?.compactMap { name in + switch name.kind { + case .long: return "--" + name.name + case .short, .longWithSingleDash: return "-" + name.name + } + }.first guard let name else { fatalError("Unable to find a suitable argument name for \(arg)") }