Skip to content

Commit 7517530

Browse files
johnbuteJohn Bute
andauthored
Be consistent in y/n prompts (#222)
Consistency in y/n prompts. Fixes #141. In order to avoid certain prompts to user only accepting 'y', or 'n', utilize the promptForConfirmation method to ensure consistency in user experience. --------- Co-authored-by: John Bute <johnbute@Johns-MacBook-Pro.local>
1 parent b1deb64 commit 7517530

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

Sources/Swiftly/Init.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ internal struct Init: SwiftlyCommand {
7676
These locations can be changed with SWIFTLY_HOME and SWIFTLY_BIN environment variables and run this again.
7777
\(installMsg)
7878
""")
79-
80-
if SwiftlyCore.readLine(prompt: "Proceed with the installation? [Y/n] ") == "n" {
79+
guard SwiftlyCore.promptForConfirmation(defaultBehavior: true) else {
8180
throw SwiftlyError(message: "Swiftly installation has been cancelled")
8281
}
8382
}
@@ -93,9 +92,7 @@ internal struct Init: SwiftlyCommand {
9392
SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
9493
}
9594

96-
let proceed = SwiftlyCore.readLine(prompt: "Proceed? [y/N]") ?? "n"
97-
98-
guard proceed == "y" else {
95+
guard SwiftlyCore.promptForConfirmation(defaultBehavior: false) else {
9996
throw SwiftlyError(message: "Swiftly installation has been cancelled")
10097
}
10198
}
@@ -203,8 +200,12 @@ internal struct Init: SwiftlyCommand {
203200
try FileManager.default.createDirectory(at: confDir, withIntermediateDirectories: true)
204201
profileHome = confDir.appendingPathComponent("swiftly.fish", isDirectory: false)
205202
} else {
206-
let confDir = userHome.appendingPathComponent(".config/fish/conf.d", isDirectory: true)
207-
try FileManager.default.createDirectory(at: confDir, withIntermediateDirectories: true)
203+
let confDir = userHome.appendingPathComponent(
204+
".config/fish/conf.d", isDirectory: true
205+
)
206+
try FileManager.default.createDirectory(
207+
at: confDir, withIntermediateDirectories: true
208+
)
208209
profileHome = confDir.appendingPathComponent("swiftly.fish", isDirectory: false)
209210
}
210211
} else {

Sources/Swiftly/Install.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ struct Install: SwiftlyCommand {
266266
SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
267267
}
268268

269-
let proceed = SwiftlyCore.readLine(prompt: "Proceed? [y/N]") ?? "n"
270-
271-
guard proceed == "y" else {
269+
guard SwiftlyCore.promptForConfirmation(defaultBehavior: false) else {
272270
throw SwiftlyError(message: "Toolchain installation has been cancelled")
273271
}
274272
}

0 commit comments

Comments
 (0)