Skip to content

Commit

Permalink
Be consistent in y/n prompts (#222)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
johnbute and John Bute authored Feb 11, 2025
1 parent b1deb64 commit 7517530
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Sources/Swiftly/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ internal struct Init: SwiftlyCommand {
These locations can be changed with SWIFTLY_HOME and SWIFTLY_BIN environment variables and run this again.
\(installMsg)
""")

if SwiftlyCore.readLine(prompt: "Proceed with the installation? [Y/n] ") == "n" {
guard SwiftlyCore.promptForConfirmation(defaultBehavior: true) else {
throw SwiftlyError(message: "Swiftly installation has been cancelled")
}
}
Expand All @@ -93,9 +92,7 @@ internal struct Init: SwiftlyCommand {
SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
}

let proceed = SwiftlyCore.readLine(prompt: "Proceed? [y/N]") ?? "n"

guard proceed == "y" else {
guard SwiftlyCore.promptForConfirmation(defaultBehavior: false) else {
throw SwiftlyError(message: "Swiftly installation has been cancelled")
}
}
Expand Down Expand Up @@ -203,8 +200,12 @@ internal struct Init: SwiftlyCommand {
try FileManager.default.createDirectory(at: confDir, withIntermediateDirectories: true)
profileHome = confDir.appendingPathComponent("swiftly.fish", isDirectory: false)
} else {
let confDir = userHome.appendingPathComponent(".config/fish/conf.d", isDirectory: true)
try FileManager.default.createDirectory(at: confDir, withIntermediateDirectories: true)
let confDir = userHome.appendingPathComponent(
".config/fish/conf.d", isDirectory: true
)
try FileManager.default.createDirectory(
at: confDir, withIntermediateDirectories: true
)
profileHome = confDir.appendingPathComponent("swiftly.fish", isDirectory: false)
}
} else {
Expand Down
4 changes: 1 addition & 3 deletions Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ struct Install: SwiftlyCommand {
SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)")
}

let proceed = SwiftlyCore.readLine(prompt: "Proceed? [y/N]") ?? "n"

guard proceed == "y" else {
guard SwiftlyCore.promptForConfirmation(defaultBehavior: false) else {
throw SwiftlyError(message: "Toolchain installation has been cancelled")
}
}
Expand Down

0 comments on commit 7517530

Please sign in to comment.