Skip to content

Commit 70fcf24

Browse files
authored
Partial warning cleanup: remove unused awaits and refactor argument parsing (#398)
* Remove unnecessary 'await' where no async operations occur * Silence unused variable warnings * 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.
1 parent 2fe2101 commit 70fcf24

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Sources/MacOSPlatform/MacOS.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public struct MacOS: Platform {
117117

118118
if ctx.mockedHomeDir == nil {
119119
await ctx.message("Extracting the swiftly package...")
120-
try await sys.installer(
120+
_ = sys.installer(
121121
.pkg(archive),
122122
.target("CurrentUserHomeDirectory")
123123
)
@@ -193,7 +193,7 @@ public struct MacOS: Platform {
193193
}
194194

195195
public func getShell() async throws -> String {
196-
for (key, value) in try await sys.dscl(datasource: ".").read(path: fs.home, key: ["UserShell"]).properties(self) {
196+
for (_, value) in try await sys.dscl(datasource: ".").read(path: fs.home, key: ["UserShell"]).properties(self) {
197197
return value
198198
}
199199

Sources/SwiftlyCore/ModeledCommandLine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ extension Runnable {
181181
newEnv = newValue
182182
}
183183

184-
try await p.runProgram([executable] + args, quiet: quiet, env: newEnv)
184+
try p.runProgram([executable] + args, quiet: quiet, env: newEnv)
185185
}
186186
}
187187

Tools/generate-command-models/GenerateCommandModels.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct GenerateCommandModels: AsyncParsableCommand {
7070
"""
7171
}
7272

73-
try await allCmds.write(to: URL(fileURLWithPath: self.outputFile), atomically: true, encoding: .utf8)
73+
try allCmds.write(to: URL(fileURLWithPath: self.outputFile), atomically: true, encoding: .utf8)
7474
}
7575

7676
struct Vars {
@@ -176,14 +176,12 @@ struct GenerateCommandModels: AsyncParsableCommand {
176176

177177
private func argSwitchCase(_ arg: ArgumentInfoV0) -> String {
178178
let flag = arg.kind == .flag
179-
var name: String?
180-
if let longName = arg.names?.filter { $0.kind == .long }.first?.name {
181-
name = "--" + longName
182-
} else if let shortName = arg.names?.filter { $0.kind == .short }.first?.name {
183-
name = "-" + shortName
184-
} else if let longNameWithSingleDash = arg.names?.filter { $0.kind == .longWithSingleDash }.first?.name {
185-
name = "-" + longNameWithSingleDash
186-
}
179+
let name: String? = arg.names?.compactMap { name in
180+
switch name.kind {
181+
case .long: return "--" + name.name
182+
case .short, .longWithSingleDash: return "-" + name.name
183+
}
184+
}.first
187185

188186
guard let name else { fatalError("Unable to find a suitable argument name for \(arg)") }
189187

0 commit comments

Comments
 (0)