Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush after prompt #4063

Merged
merged 1 commit into from Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.md
Expand Up @@ -38,6 +38,9 @@ Bug fixes:
was tried to be registered. This is now fixed by always building internal
libraries. See
[#3996](https://github.com/commercialhaskell/stack/issues/3996).
* When prompting users about saving their Hackage credentials on upload,
flush to stdout before waiting for the response so the prompt actually
displays.


## v1.7.1
Expand Down
24 changes: 10 additions & 14 deletions src/Stack/Upload.hs
Expand Up @@ -99,28 +99,24 @@ loadCreds config = do

when (configSaveHackageCreds config) $ do
let prompt = "Save hackage credentials to file at " ++ fp ++ " [y/n]? "
putStr prompt
input <- loopPrompt prompt
putStrLn "NOTE: Avoid this prompt in the future by using: save-hackage-creds: false"
hFlush stdout
case input of
"y" -> do
L.writeFile fp (encode hc)
putStrLn "Saved!"
hFlush stdout
_ -> return ()
when input $ do
L.writeFile fp (encode hc)
putStrLn "Saved!"
hFlush stdout

return hc

loopPrompt :: String -> IO String
loopPrompt :: String -> IO Bool
loopPrompt p = do
putStr p
hFlush stdout
input <- TIO.getLine
case input of
"y" -> return "y"
"n" -> return "n"
_ -> do
putStr p
loopPrompt p
"y" -> return True
"n" -> return False
_ -> loopPrompt p

credsFile :: Config -> IO FilePath
credsFile config = do
Expand Down