diff --git a/src/Config.idr b/src/Config.idr index 32eee41..92a7a4a 100644 --- a/src/Config.idr +++ b/src/Config.idr @@ -215,14 +215,14 @@ createConfig envGithubPAT terminalColors editor = do putStrLn "What GitHub remote repo would you like to use harmony for\{remoteDefaultStr}?" defaultRemote <- Just . orIfEmpty (Just remoteGuess) . trim <$> getLine - putStr "Would you like harmony to comment when it assigns reviewers? [Y/n] " - commentOnAssign <- yesUnlessNo . trim <$> getLine + commentOnAssign <- + yesNoPrompt "Would you like harmony to comment when it assigns reviewers?" - putStr "Would you like harmony to assign teams when it assigns reviewers? [Y/n] " - assignTeams <- yesUnlessNo . trim <$> getLine + assignTeams <- + yesNoPrompt "Would you like harmony to assign teams when it assigns reviewers?" - putStr "Would you like harmony to assign individual users when it assigns reviewers? [Y/n] " - assignUsers <- yesUnlessNo . trim <$> getLine + assignUsers <- + yesNoPrompt "Would you like harmony to assign individual users when it assigns reviewers?" _ <- liftIO $ octokit pat putStrLn "Creating config..." @@ -263,12 +263,6 @@ createConfig envGithubPAT terminalColors editor = do orIfEmpty (Just y) "" = y orIfEmpty (Just _) x = x - yesUnlessNo : String -> Bool - yesUnlessNo answer with (toLower answer) - _ | "n" = False - _ | "no" = False - _ | _ = True - org : Maybe GitRemote -> Maybe String org = map (.org) diff --git a/src/Util.idr b/src/Util.idr index f3404cd..f9ec659 100644 --- a/src/Util.idr +++ b/src/Util.idr @@ -39,6 +39,21 @@ getManyLines = getMoreLines [] ("" :: rest, "") => pure (reverse rest) _ => getMoreLines (line :: acc) fuel +||| Ask a question and receive a yes/no response with yes being the default. +||| You probably want your question String to end with a question mark; +||| @yesNoPrompt@ will append "[Y/n]" to the end of your question for you. +export +yesNoPrompt : HasIO io => (question : String) -> io Bool +yesNoPrompt question = do + putStr "\{question} [Y/n] " + yesUnlessNo . trim <$> getLine + where + yesUnlessNo : String -> Bool + yesUnlessNo answer with (toLower answer) + _ | "n" = False + _ | "no" = False + _ | _ = True + ||| Get an absolute path for the given directory or file assuming the ||| given path is relative to the root of the Git repository. export